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

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

    Here's how it looks like:

    Thanks.

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

Similar Threads

  1. [SOLVED] Adding JTree, JTable inside a JTabbedPane
    By javanewbie in forum AWT / Swing
    Replies: 6
    Last Post: 05-28-2009, 05:32 AM
  2. Problem Adding Content To JTabbedPane
    By JDCAce in forum AWT / Swing
    Replies: 5
    Last Post: 10-18-2008, 09:45 AM
  3. Adding file contents to Choice component
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-07-2008, 09:06 AM
  4. Adding information to a JTable in a JTabbedPane
    By bigpappatrader in forum AWT / Swing
    Replies: 0
    Last Post: 12-05-2007, 07:09 AM
  5. Adding Tabs to JTabbedPane
    By blackstone in forum AWT / Swing
    Replies: 2
    Last Post: 11-14-2007, 03: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
  •