Adding a Table to a Container
by, 04-26-2012 at 08:43 PM (512 Views)
Scroll pane creation has a typical code which servers to be a container, for a table.
In this snippet, 2 lines would be doing the given:Java Code:JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true);
• Along with an argument, constructor JScrollPane would be invoked which will be referring to the table objects. A scroll pane would be created as a container for sake of table; automatically addition of the table would be done to the container.
• For setting up the property fillsViewportHeight, invoke JTable.setFillsViewportHeight.Entire container’s height is used by the table when property turns out to be true. Even when enough rows are absent in table to be used in vertical space. In this wasy table is easily used as drag & drop target.
Table header is placed automatically at the viewport’s top. Name of the column stays visible at the view area’s top when the data of table is being scrolled.
If you are using a table without a scroll pane, then you must get the table header component and place it yourself. For example:
When table is being used with no scroll pane, table header component shall be obtained and placed you. For instance
Java Code:container.setLayout(new BorderLayout()); container.add(table.getTableHeader(), BorderLayout.PAGE_START); container.add(table, BorderLayout.CENTER);