Example usage for javax.swing JTable setFillsViewportHeight

List of usage examples for javax.swing JTable setFillsViewportHeight

Introduction

In this page you can find the example usage for javax.swing JTable setFillsViewportHeight.

Prototype

@BeanProperty(description = "Whether or not this table is always made large enough to fill the height of an enclosing viewport")
public void setFillsViewportHeight(boolean fillsViewportHeight) 

Source Link

Document

Sets whether or not this table is always made large enough to fill the height of an enclosing viewport.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(2, 3));

    JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton getQuotesButton = new JButton("Load");
    buttonConstrsint.add(getQuotesButton);
    gui.add(buttonConstrsint, BorderLayout.NORTH);

    getQuotesButton.addActionListener(e -> {
        String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

        Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) },
                { "C", "D", "Pool", new Integer(10), new Boolean(false) } };

        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);

        gui.add(scrollPane, BorderLayout.CENTER);
        gui.revalidate();/*from  w  w w. j  a v  a  2s  .co m*/
        gui.repaint();
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

    JDialog dialog = jOptionPane.createDialog(new JFrame(), "title");
    dialog.setSize(200, 200);
    dialog.setVisible(true);
}

From source file:de.codesourcery.eve.skills.ui.spreadsheet.SpreadSheetTableModel.java

public static void main(String[] args) {

    final ITableFactory cellFactory = new ITableFactory() {

        @Override// w w  w.ja va2  s .  c  om
        public ITableCell createEmptyCell(int row, int column) {
            return new SimpleCell();
        }

        @Override
        public TableRow createRow(SpreadSheetTableModel tableModel) {
            return new TableRow(tableModel);
        }

    };

    final SpreadSheetTableModel model = new SpreadSheetTableModel(cellFactory);

    final JTable table = new JTable(model);

    table.setFillsViewportHeight(true);

    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //      table.setPreferredSize( new Dimension(400,200 ) );
    table.setBorder(BorderFactory.createLineBorder(Color.black));

    frame.getContentPane().add(new JScrollPane(table));

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            frame.pack();
            frame.setLocationRelativeTo(null);

            frame.setVisible(true);

            model.addRow(new SimpleCell("First row") {
                public boolean isEditable() {
                    return true;
                }

                public void setValue(Object value) {
                    System.out.println("new value: " + value);
                }
            });
            model.addRow(new SimpleCell("Second row #1"), new SimpleCell("Second row #2"));
            model.addRow(new SimpleCell("Third row #1"), new SimpleCell("Third row #2"),
                    new SimpleCell("Third row #3"));

            JTextField tf = new JTextField();

            table.setModel(model);
            table.setDefaultEditor(ITableCell.class, new DefaultCellEditor(tf));
        }
    });

}

From source file:eu.cassandra.csn.gui.Stats.java

/**
 * //from ww w  .  j a va 2  s  .  c  om
 * @param frame
 */
public static JPanel setNetworkStats(JFrame frame) {
    String[][] data = new String[][] { { "Virtual Days:", "" }, { "Number of nodes:", "" },
            { "Number of edges:", "" }, { "Graph diameter:", "" }, { "Vertex Betweenness Centrality:", "" },
            { "Edge Betweenness Centrality:", "" }, { "Total consumption:", "" },
            { "Average consumption:", "" }, { "Peak consumption:", "" }, { "Unconnected vertices:", "" },
            { "Clusters:", "" } };
    String[] columnName = new String[] { "Metric", "Value" };

    tableModel = new MyDefaultTableModel(data, columnName);
    JTable table = new JTable(tableModel);
    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);

    String[][] dataSelected = new String[5][];
    String[] columnNameSelected = new String[] { "Name", "Type", "Total Consumption", "Peak Comsumption",
            "Avg Consumption" };
    tableModelSelected = new MyDefaultTableModel(dataSelected, columnNameSelected);
    JTable tableSelected = new JTable(tableModelSelected);
    JScrollPane scrollPaneSelected = new JScrollPane(tableSelected);
    tableSelected.setFillsViewportHeight(true);
    tableSelected.setPreferredSize(new Dimension(1600, 100));
    scrollPaneSelected.setPreferredSize(new Dimension(1600, 100));

    JPanel statsPanel = new JPanel(new BorderLayout());
    statsPanel.add(scrollPane, BorderLayout.CENTER);
    chartPanel = Charts.createGraph("Power Consumption", "Hours", "Power (W)", new Double[0]);

    statsPanel.add(chartPanel, BorderLayout.PAGE_END);

    //frame.add(statsPanel,BorderLayout.EAST);
    frame.add(scrollPaneSelected, BorderLayout.PAGE_END);
    return statsPanel;
}

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);

    if (DEBUG) {// w ww.jav a2  s .c o m
        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: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);

    //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 w  w w .  j a  v  a2s . c  o  m
}

From source file:components.TableSortDemo.java

public TableSortDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);/*from   w  ww.ja va  2  s  .  c o  m*/

    //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:components.TableDialogEditDemo.java

public TableDialogEditDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Set up renderer and editor for the Favorite Color column.
    table.setDefaultRenderer(Color.class, new ColorRenderer(true));
    table.setDefaultEditor(Color.class, new ColorEditor());

    //Add the scroll pane to this panel.
    add(scrollPane);// ww w . ja va 2  s .  c  o m
}

From source file:components.TableFTFEditDemo.java

public TableFTFEditDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Set up stricter input validation for the integer column.
    table.setDefaultEditor(Integer.class, new IntegerEditor(0, 100));

    //If we didn't want this editor to be used for other
    //Integer columns, we'd do this:
    //table.getColumnModel().getColumn(3).setCellEditor(
    //   new IntegerEditor(0, 100));

    //Add the scroll pane to this panel.
    add(scrollPane);//w  w w .ja  v a2 s . c  o  m
}

From source file:customprogressindicatordemo.WeatherData.java

public WeatherData() {
    setBackground(Color.WHITE);/*from   w  w  w .  j  ava 2 s. c  om*/
    setLayout(new BorderLayout());
    JLabel lbl = new JLabel("World-Wide Weather Data");
    add(lbl, BorderLayout.NORTH);

    String[] columnNames = { "City", "Temperature" };
    JTable table = new JTable(getData(), columnNames);

    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBackground(Color.WHITE);

    //Add the scroll pane to this panel.
    add(scrollPane, BorderLayout.SOUTH);
}

From source file:components.TableRenderDemo.java

public TableRenderDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Set up column sizes.
    initColumnSizes(table);/*w  ww .  jav a2  s .  c  om*/

    //Fiddle with the Sport column's cell editors/renderers.
    setUpSportColumn(table, table.getColumnModel().getColumn(2));

    //Add the scroll pane to this panel.
    add(scrollPane);
}