Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By milovan
  • 1 Post By DarrylBurke

Thread: JButton doesnt show unless you move mouse over it

  1. #1
    liluma's Avatar
    liluma is offline Member
    Join Date
    May 2011
    Location
    belgium
    Posts
    50
    Rep Power
    0

    Default JButton doesnt show unless you move mouse over it

    like said

    so all my buttons get created... but I can't see them unless i move my mouse over the place where they are...
    then they are visible...

    this is my code
    Java Code:
    package gui;
    
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    
    import domein.DomeinController;
    
    public class StartFrame extends JFrame
    {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 2823954135081527346L;
    	private DomeinController domCntrl;
    	private JButton size450, size512, size600;
    	
    	public StartFrame(DomeinController domCntrl)
    	{
    		super("connect the dots");
    		setDomeinController(domCntrl);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setSize(400,400);
    		setResizable(false);
    		setLocationRelativeTo(null);
    		setVisible(true);
    		setLayout(null);
    		initGUI();
    	}
    	
    	private void initGUI()
    	{
    		int midX = this.getWidth()/2-50;
    		size450 = new JButton("450*450");
    		size450.setBounds(midX, 110, 100,25);
    		size450.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent arg0) 
    			{
    				JOptionPane.showMessageDialog(null, "pressed Button size450");
    			}		
    		});
    		size512 = new JButton("512*512");
    		size512.setBounds(midX, 160, 100, 25);
    		size512.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent arg0) 
    			{
    				JOptionPane.showMessageDialog(null, "pressed Button size512");
    			}		
    		});
    		size600 = new JButton("600*600");
    		size600.setBounds(midX, 210, 100, 25);
    		size600.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent arg0) 
    			{
    				JOptionPane.showMessageDialog(null, "pressed Button size600");
    			}		
    		});
    		
    		this.add(size450);
    		this.add(size512);
    		this.add(size600);
    	}
    	
    	public void paint(Graphics g)
    	{
    		g.fillRect(0,0,getWidth(),getHeight());
    	}
    	
    	private void setDomeinController(DomeinController p_dom)
    	{
    		this.domCntrl = p_dom;
    	}
    }
    someone who has an idea what i did wrong? :o :(

    all help is appreciated. ^^

    grtz lil

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: JButton doesnt show unless you move mouse over it

    try to call setVisible() after initGUI().
    Fubarable likes this.

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

    Default Re: JButton doesnt show unless you move mouse over it

    1. Don't override paint(..) of a top level window. Do invoke the super implementation at the start of any painting method override (unless you are supremely confident that it's not needed).

    2. Don't use a null layout. Learn to use the layout managers: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    And what milovan said.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    liluma's Avatar
    liluma is offline Member
    Join Date
    May 2011
    Location
    belgium
    Posts
    50
    Rep Power
    0

    Default Re: JButton doesnt show unless you move mouse over it

    k ty ^^

    will give it a try.

    thnks for helping me. tho is a layout recommended? since i'll be use final positions...
    grtz liluma

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

Similar Threads

  1. Last JLabel I add to JPanel doesnt show up
    By Ambergahill in forum New To Java
    Replies: 6
    Last Post: 01-29-2014, 08:07 PM
  2. Applet doesnt start or it doesnt show
    By 3dprogger in forum Java Applets
    Replies: 2
    Last Post: 01-07-2011, 07:03 PM
  3. combobox doesnt show!
    By LennyKosmos in forum New To Java
    Replies: 2
    Last Post: 10-26-2010, 08:07 PM
  4. doesnt show exact size
    By clydedoris in forum NetBeans
    Replies: 3
    Last Post: 07-13-2010, 06:59 AM
  5. JTable doesnt show columun names!
    By phil128 in forum AWT / Swing
    Replies: 3
    Last Post: 03-08-2009, 10:39 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
  •