Results 1 to 3 of 3
  1. #1
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Question GUI Problem with setBounds();

    Hello, I am creating a startscreen for a project,

    I can't seem to get the setBounds() methods to work. I want all three buttons to be the same width but it just isn't happening. They are all remaining at their default width.

    Can anyone see what is wrong?

    Java Code:
    package Start;
    
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class StartScreen extends JFrame {
    	
    	//CONSTRUCTOR
    	public StartScreen(){
    		super("Start");
    		loadUI();
    	}
    	
    	//UI
    	private void loadUI(){
    		Font font = new Font("Arial", Font.BOLD, 14);
    		
    		//JFRAME
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setResizable(false);
    		setSize(340, 63);
    		setLocationRelativeTo(null);
    		
    		//JPANEL
    		JPanel panel = new JPanel();
    		
    		//BUTTONS
    		JButton login = new JButton("Login");
    		login.setBounds(10, 10, 100, 25);
    		login.setFont(font);
    		panel.add(login);
    		//
    		JButton register = new JButton("Register");
    		register.setBounds(115, 10, 100, 25);
    		register.setFont(font);
    		panel.add(register);
    		//
    		JButton exit = new JButton("Exit");
    		exit.setBounds(230, 10, 100, 25);
    		exit.setFont(font);
    		panel.add(exit);
    		
    		//JPANEL
    		add(panel);
    		
    		//JFRAME
    		setVisible(true);
    		
    		//EVENT HANDLING
    		login.addActionListener(
    				new ActionListener(){
    					public void actionPerformed(ActionEvent e) {
    						LoginScreen l = new LoginScreen();
    						dispose();
    					}
    				}
    		);
    		register.addActionListener(
    				new ActionListener(){
    					public void actionPerformed(ActionEvent e) {
    						RegScreen r = new RegScreen();
    						dispose();
    					}
    				}
    		);
    		exit.addActionListener(
    				new ActionListener(){
    					public void actionPerformed(ActionEvent e) {
    						System.exit(0);
    					}
    				}
    		);
    		
    	}
    	
    	public static void main(String[] args){
    		StartScreen s = new StartScreen();
    	}
    }

  2. #2
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    dw, I figured it out, I forgot to put null into my JPanel constructor call

    Java Code:
    JPanel panel = new JPanel(null);

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

Similar Threads

  1. How to setBounds for a tableItem
    By crisfromnova in forum SWT / JFace
    Replies: 0
    Last Post: 06-25-2010, 03:53 PM
  2. control setLocation setBounds
    By xna in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 05:29 AM
  3. Positioning using setBounds
    By thayalan in forum AWT / Swing
    Replies: 4
    Last Post: 04-28-2009, 02:59 AM
  4. Using setBounds (x.y,width,height) constructor
    By hitmen in forum AWT / Swing
    Replies: 3
    Last Post: 03-06-2009, 01:12 PM
  5. Problem here guys: Set location or setBounds
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-03-2008, 08:19 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
  •