Thread: GUI trouble

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2

    GUI trouble


    Hi. I have a little problem with location of my toolbar and menubar. One of them overlays the other. So i want you to ask how i can add two of them usin borderlayout ? If it's difficult with BorderLayout please guide me in the right direction.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,664
    Rep Power
    1958
    You will have to use several JPanels and Layouts.

    For example something like this:
    1. Use BorderLayout to specify that top part (NORTH) for the menu
    2. If you want something below each other, a Grid layout could be useful for this, so create one JPanel with this layout and add it to NORTH.
    2. Next is to add a JPanel to each cell in the Grid, where each JPanel has it own menu/toolbar.

    If you want more specific help/answer, you should post the code you have tried and/or have issues with.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2
    Here is it. I hope it wont be deleted now.
    main:
    Code:
    import java.awt.*;
    import javax.swing.*;
    
    class root{
    	
    	public static void main(String[] args){
    		
    		//frame parameters
    		JFrame mainFrame = new JFrame("Journal B");
    		mainFrame.setVisible(true);
    		mainFrame.setSize(1000,600);
    		
    		//content objects
    		MMenu menu = new MMenu();
    		MTable tab = new MTable();
    		
    		//components addition
    		mainFrame.add(menu,BorderLayout.NORTH);
    		mainFrame.add(tab,BorderLayout.SOUTH);
    		
    		
    		
    	}
    	
    }
    menu:
    Code:
    import javax.swing.*;
    import javax.swing.*;
    
    
    class MMenu extends JMenuBar{
    	
    	JMenuItem openItem = new JMenuItem("Open");
    	JMenu openMenu = new JMenu("File");;
    	
    	public MMenu(){		
    		
    
    		openMenu.add(openItem);
    		add(openMenu);
    	}
    }
    Tool Bar
    Code:
    import javax.swing.*;
    
    //result table 
    class MTable extends JTable{
    
    	public MTable(){
    		
    		setSize(950, 400);
    	}
    
    }
    U see, my another problem is : when i'm adding the comentation my gui disapears. after 3-10 ctr+s it becomes normal . if i ctrl+s 1-2 times gui doesn't appears. i wrote that in "Gui Magic" thread.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2
    If i adding my tab or just declaring it's creation - menu disappears. I mean if i write only this :
    MTable tab = new MTable().
    without adding on frame - menu disapears.
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,664
    Rep Power
    1958
    Tried you code, and made some changes to the root class: (see the code comments)
    java Code:
     
    import java.awt.*;
    import javax.swing.*;
     
    class Root{
     
    	public static void main(String[] args){
     
    		//frame parameters
    		JFrame mainFrame = new JFrame("Journal B");
    		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // proper closing of the program
     
    		mainFrame.setSize(1000,600);
     
    		//content objects
    		MMenu menu = new MMenu();
    		MTable tab = new MTable();
     
    		//components addition
    		mainFrame.add(menu,BorderLayout.NORTH);
    		mainFrame.add(tab,BorderLayout.SOUTH);		
     
    		mainFrame.setVisible(true); // show the frame after all things had been added
    	}
     
    }


    Not sure what you want to do with MTable and why you added it to SOUTH.

IMN logo majestic logo threadwatch logo seochat tools logo