Results 1 to 7 of 7
  1. #1
    javanewbie is offline Member
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    43
    Rep Power
    0

    Question [SOLVED] Adding JTree, JTable inside a 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
    Java 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

    Java 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

    Java 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

    Java 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) inside the 'Tree' tab and 'ServiceCallTable' (Table) inside the 'Table' tab?

    Here's how it looks like:

    Thanks.
    Last edited by javanewbie; 05-27-2009 at 06:36 AM.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    javanewbie is offline Member
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    43
    Rep Power
    0

    Default

    Already read about that one. But you see, the process only displays texts in each tab.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    javanewbie is offline Member
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    43
    Rep Power
    0

    Default

    Not quite I am looking for but it's a good headstart.

    Any more resource/s I could possibly get?

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Looks like the examples in the tutorials should be enough (they're all listed at the bottom of the Tabbed Panes page)
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I don't see definitions of treePanel and tablePanel, nor do I see how anything gets added to contentPane, so I can't really comment too much.

    However, I would make each "tab" component a JPanel and then add the tree and table components to the JPanel's.

    Also, if the JTabbedPane is the top level component, I would make sure it fills the content pane. I generally do this by setting the layout manager of the content pane to GridLayout with no parameters, which cause the component placed in the content pane to fill the pane.

Similar Threads

  1. Problem Adding Content To JTabbedPane
    By JDCAce in forum AWT / Swing
    Replies: 5
    Last Post: 10-18-2008, 10:45 AM
  2. Replies: 0
    Last Post: 08-29-2008, 01:49 PM
  3. Replies: 0
    Last Post: 08-29-2008, 01:16 PM
  4. Adding information to a JTable in a JTabbedPane
    By bigpappatrader in forum AWT / Swing
    Replies: 0
    Last Post: 12-05-2007, 08:09 AM
  5. Adding Tabs to JTabbedPane
    By blackstone in forum AWT / Swing
    Replies: 2
    Last Post: 11-14-2007, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •