List of usage examples for javax.swing JTable setPreferredScrollableViewportSize
@BeanProperty(bound = false, description = "The preferred size of the viewport.") public void setPreferredScrollableViewportSize(Dimension size)
From source file:Main.java
public static void main(String args[]) { JTable table = new JTable(22, 5); table.setPreferredScrollableViewportSize(new Dimension(400, 300)); final JScrollPane scrollPane = new JScrollPane(table); JButton cornerButton = new JButton("#"); scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JFrame frame = new JFrame(); frame.add(scrollPane);/*from w w w .ja va 2s.c o m*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int maximum = 100; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Integer[] oneRow = { 0, 0, 0, 0 }; String[] headers = { "A", "B", "C", "D" }; Integer[][] data = { oneRow, oneRow, oneRow, oneRow, oneRow, }; DefaultTableModel model = new DefaultTableModel(data, headers); JTable table = new JTable(model); table.setDefaultRenderer(Object.class, new ProgressRenderer(0, maximum)); table.setPreferredScrollableViewportSize(table.getPreferredSize()); frame.add(new JScrollPane(table)); frame.pack();/*from w w w .j a v a 2 s . c o m*/ frame.setVisible(true); new Thread(new Runnable() { @Override public void run() { Object waiter = new Object(); synchronized (waiter) { int rows = model.getRowCount(); int columns = model.getColumnCount(); Random random = new Random(System.currentTimeMillis()); boolean done = false; while (!done) { int row = random.nextInt(rows); int column = random.nextInt(columns); Integer value = (Integer) model.getValueAt(row, column); value++; if (value <= maximum) { model.setValueAt(value, row, column); try { waiter.wait(15); } catch (InterruptedException e) { e.printStackTrace(); } } done = true; for (row = 0; row < rows; row++) { for (column = 0; column < columns; column++) { if (!model.getValueAt(row, column).equals(maximum)) { done = false; break; } } if (!done) { break; } } } } } }).start(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] columns = { "Name", "Age" }; Object[][] content = { { "R", new Integer(24) }, { "A", new Integer(25) }, { "J", new Integer(30) }, { "A", new Integer(32) }, { "S", new Integer(27) } }; JTable table = new JTable(content, columns); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jPanel = new JPanel(new GridLayout(2, 0)); jPanel.setOpaque(true);//from w ww . ja v a 2 s . c o m table.setPreferredScrollableViewportSize(new Dimension(500, 70)); jPanel.add(new JScrollPane(table)); /* Add the panel to the JFrame */ frame.add(jPanel); /* Display the JFrame window */ frame.pack(); frame.setVisible(true); table.print(); }
From source file:Main.java
public static void main(String[] args) { JTable table = new JTable(5, 5) { @Override/*from w ww.jav a 2s.c o m*/ public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); ((JLabel) comp).setHorizontalAlignment(JLabel.RIGHT); return comp; } }; table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); JFrame f = new JFrame(); f.getContentPane().add(scrollPane); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:TableDemoApplet.java
private static void createGUI(Container contentPane) { Object[][] rowData = new String[][] { { "98-43", "AraAra! SL" }, { "81-31", "Aragones Transports SA" }, { "12-72", "Rocca SL" }, { "99-10", "Rodriguez e Hijos SA" }, { "00-65", "Rimbau Motors SL" } }; JTable table = new JTable(rowData, new String[] { "Part No", "Provider" }); JComboBox companyComboBox = new JComboBox(new Object[] { "AraAra! SL", "Aragones Transports SA", "Rocca SL", "Rodriguez e Hijos SA", "Rimbau Motors SL" }); companyComboBox.setEditable(true);/*from w w w. j a v a 2s .c om*/ new S15WorkingBackspace(companyComboBox); // setup the ComboBoxCellEditor, DefaultCellEditor won't work! table.getColumnModel().getColumn(1).setCellEditor(new ComboBoxCellEditor(companyComboBox)); table.setPreferredScrollableViewportSize(new Dimension(400, 100)); JScrollPane scrollPane = new JScrollPane(table); contentPane.setLayout(new java.awt.FlowLayout()); contentPane.add(scrollPane); contentPane.add(new JTextField("HALLO!")); }
From source file:org.apache.taverna.activities.rest.ui.config.RESTActivityConfigurationPanel.java
public static void setVisibleRowCount(JTable table, int visibleRows) { int height = 0; for (int row = 0; row < visibleRows; row++) height += table.getRowHeight(row); table.setPreferredScrollableViewportSize( new Dimension(table.getPreferredScrollableViewportSize().width, height)); }
From source file:components.SimpleTableDemo.java
public SimpleTableDemo() { super(new GridLayout(1, 0)); String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) }, { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) }, { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) }, { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) }, { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);//w w w . ja va2 s .co m if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:Main.java
/** * Setups the given table for usage as row-header. This method setups the background color to * the same one than the column headers. * * {@note In a previous version, we were assigning to the row headers the same cell renderer than * the one created by <cite>Swing</cite> for the column headers. But it produced strange * effects when the L&F uses a vertical grandiant instead than a uniform color.} * * @param table The table to setup as row headers. * @return The renderer which has been assigned to the table. *//*from ww w . j av a 2 s. co m*/ public static TableCellRenderer setupAsRowHeader(final JTable table) { final JTableHeader header = table.getTableHeader(); Color background = header.getBackground(); Color foreground = header.getForeground(); if (background == null || background.equals(table.getBackground())) { if (!SystemColor.control.equals(background)) { background = SystemColor.control; foreground = SystemColor.controlText; } else { final Locale locale = table.getLocale(); background = UIManager.getColor("Label.background", locale); foreground = UIManager.getColor("Label.foreground", locale); } } final DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setBackground(background); renderer.setForeground(foreground); renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); final TableColumn column = table.getColumnModel().getColumn(0); column.setCellRenderer(renderer); column.setPreferredWidth(60); table.setPreferredScrollableViewportSize(table.getPreferredSize()); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(false); return renderer; }
From source file:Main.java
public Main() { ImageIcon aboutIcon = new ImageIcon("about16.gif"); ImageIcon addIcon = new ImageIcon("add16.gif"); ImageIcon copyIcon = new ImageIcon("copy16.gif"); String[] columnNames = { "Picture", "Description" }; Object[][] data = { { aboutIcon, "About" }, { addIcon, "Add" }, { copyIcon, "Copy" }, }; DefaultTableModel model = new DefaultTableModel(data, columnNames); JTable table = new JTable(model) { public Class getColumnClass(int column) { return (column == 0) ? Icon.class : Object.class; }//from w w w. j a va 2s . c o m }; table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane); }
From source file:components.TableDemo.java
public TableDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);// w w w. j a v a 2s. c om //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }