Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Jtabbed Pane not taking entire space

  1. #1
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Jtabbed Pane not taking entire space

    Hello, I am trying to make a JTabPane, but the problem is that the tabs are not taking up the entire size of the Frame in which they are contained.

    Jtabbed Pane not taking entire space-javaerror.jpg

    Here is the code

    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.SwingUtilities;
    
    import java.awt.FlowLayout;
    import java.awt.event.*; 
    
    
    public class BackupHandlerGUI extends JFrame {
    	
    	public static void main(String[] args){
    		JFrame mainFrame = new JFrame(); 
    		mainFrame.setLayout(new FlowLayout()); 
    		mainFrame.setSize(300, 300); 
    		mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		 
    		mainFrame.add(new JTab());
    		
    		mainFrame.setVisible(true); 
    		 
    	}
    	
    }
    
    
    class JTab extends JPanel{
    	
    	public JTab() {
    		try{
    			SwingUtilities.invokeAndWait(new Runnable() {
    				public void run() {
    					makeGUI();
    				}
    			}); 
    		} catch (Exception e){
    			System.err.println(e.getMessage());
    		}
    	}
    	
    	
    	private void makeGUI(){
    		JTabbedPane jtp = new JTabbedPane();
    		
    		jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    		jtp.setSize(300, 300); 
    		jtp.addTab("Download", new downloadPanel());
    		
    		jtp.addTab("Upload", new uploadPanel()); 
    		add(jtp); 
    	}
    	
    }
    
    
    class downloadPanel extends JPanel {
    	
    	public downloadPanel(){
    		 
    		JLabel myLabel = new JLabel("Test Label");
    		add(myLabel); 
    	}
    }
    
    class uploadPanel extends JPanel {
    	
    	public uploadPanel(){
    		 
    		JLabel myLabel = new JLabel("Second test Label");
    		add(myLabel); 
    	}
    }
    I am following a tutorial on how to use JTabPanes. Thank you for any help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Jtabbed Pane not taking entire space

    Hm:
    Java Code:
    mainFrame.setLayout(new FlowLayout());
    It's almost like shooting yourself in the foot and then asking why it hurts.
    Please read the layout manager tutorial to see why this layout manager's expected behavior is causing your problems. If you want layout managers that allow a container to be filled by its components, consider the GridLayout or the BorderLayout -- the latter of which was your JFrame's default layout manager before you changed it.
    DarrylBurke likes this.

  3. #3
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Jtabbed Pane not taking entire space

    I ended up not using that but instead just using panels that are removed and added as needed. Thanks for your help.

Similar Threads

  1. Adding jmenubar inside jtabbed pane
    By suresh_m5a5@yahoo.co.in in forum AWT / Swing
    Replies: 1
    Last Post: 02-25-2011, 03:10 PM
  2. JPanel inside Jtabbed isn't display
    By Ravanelly in forum Advanced Java
    Replies: 7
    Last Post: 06-08-2010, 11:19 PM
  3. get component from jtabbed pane
    By anilkumar_vist in forum New To Java
    Replies: 1
    Last Post: 12-27-2009, 08:34 PM
  4. [SOLVED] Mouse event in JTabbed Pane
    By javanewbie in forum AWT / Swing
    Replies: 6
    Last Post: 06-10-2009, 09:50 AM
  5. [SOLVED] Jtabbed pane hide a tab...?
    By prabhurangan in forum AWT / Swing
    Replies: 5
    Last Post: 08-26-2008, 09:31 AM

Posting Permissions

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