I have a createUI() function which loads JPanel into NORTH, SOUTH, EAST.
private void createUI() {
add(createToolBar(), BorderLayout.NORTH);
add(createDataView(), BorderLayout.SOUTH);
add(createHistoryView(), BorderLayout.EAST);
createMenuBar();
setTitle("My Application");
}
Each components display in the correct location, however, they are all in fixed sized JPanel. I would like to know if it's possible for the JPanel to completely fill the BorderLayout region.
For example, the createDataView() is a simple Jpanel with tables. I would like it to expand horizontally, and have a fixed height.
private JPanel createDataView(){
JPanel panel = new JPanel();
String data[][] = {{"001","vinod","Bihar","India","Biology","65","First"},
{"002","Raju","ABC","Kanada","Geography","58","second"},
{"003","Aman","Delhi","India","computer","98","Dictontion"},
{"004","Ranjan","Bangloor","India","chemestry","90","Dictontion"},
{"004","Ranjan","Bangloor","India","chemestry","90","Dictontion"}};
String col[] = {"Roll","Name","State","country","Math","Marks","Grade"};
JTable table = new JTable(data,col);
table.setPreferredScrollableViewportSize(new Dimension(900,100));
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane pane = new JScrollPane(table);
table.setAutoResizeMode(JTable.WIDTH);
table.doLayout();
panel.add(pane);
return panel;
}
Right now I am relying on manually setting the dimension. However, I would a way to get the current window width, and set it as below.
table.setPreferredScrollableViewportSize(new Dimension(900,100));