我有一個createUI()函數,它將JPanel加載到NORTH,SOUTH,EAST。Java Swing:相對定位和自動調整大小?
private void createUI() {
add(createToolBar(), BorderLayout.NORTH);
add(createDataView(), BorderLayout.SOUTH);
add(createHistoryView(), BorderLayout.EAST);
createMenuBar();
setTitle("My Application");
}
在正確的位置。每個部件顯示,但是,它們都在固定大小的JPanel。我想知道是否可以讓JPanel完全填充BorderLayout區域。
例如,createDataView()是一個帶有表格的簡單Jpanel。我希望它水平擴展,並有一個固定的高度。
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;
}
現在我正在依靠手動設置尺寸。但是,我會想辦法獲取當前窗口寬度,並將其設置爲如下所示。
table.setPreferredScrollableViewportSize(new Dimension(900,100));
你有兩件東西塞進南方「細胞」......那些應該看起來相互關聯的人是怎麼樣的? – 2010-10-05 20:00:10
添加了一些更多詳細信息... – KJW 2010-10-05 20:22:10