Adding contents inside the JTabbedPane
Hello everyone,
Is there a way I could add contents on each tab on a JTabbedPane?
Here's some part of my codes:
1. Created a tabbed pane consists of two tabs, Tree and Table
Code:
sortingTab = new JTabbedPane();
contentPane = (JPanel)this.getContentPane();
sortingTab.addTab("Tree", treePanel);
sortingTab.addTab("Table", tablePanel);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
c.gridheight = 5;
c.insets = new Insets(160,10,0,10);
pane.add(sortingTab, c);
2. Created a Tree
Code:
serviceCallTree = new ServiceCallTree();
serviceCallTree.setPreferredSize(new Dimension(10, 50));
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 2;
c.gridheight = 3;
c.insets = new Insets(80,20,5,20); //T,L,B,R
pane.add(serviceCallTree, c);
3. Created a Table
Code:
String headers[] = {"Field","Value"};
serviceCallTableData = new DefaultTableModel(null,headers){
public boolean isCellEditable(int row, int column){
return false;
}
};
serviceCallTable = new JTable(serviceCallTableData);
serviceCallTable.setAutoCreateColumnsFromModel(true);
serviceCallTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumn col = serviceCallTable.getColumnModel().getColumn(0);
col.setMinWidth(180);
col.setMaxWidth(180);
col.setPreferredWidth(180);
col = serviceCallTable.getColumnModel().getColumn(1);
col.setMinWidth(400);
col.setMaxWidth(400);
col.setPreferredWidth(400);
c.gridx = 2;
c.gridy = 1;
c.gridwidth = 4;
c.gridheight = 6;
c.insets = new Insets(75,0,0,10); //T,L,B,R
JScrollPane serviceCallScrollPane = new JScrollPane(serviceCallTable);
serviceCallScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
serviceCallScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
serviceCallScrollPane.setPreferredSize(new Dimension(600, 350));
pane.add(serviceCallScrollPane, c);
Everything (TabbedPane, Tree, Table) are inside in this method
Code:
public void addComponentsToPane(Container pane) {
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
// Codes for numbers 1,2,3, etc.
}
That is what 'c' is doing.
My question is, is there a way I could 'integrate' the 'ServiceCallTree' (Tree)(1) inside the 'Tree' tab and 'ServiceCallTable' (Table)(2) inside the 'Table' tab?
Here's how it looks like:
http://i39.tinypic.com/rtn595.jpg
Thanks.