Results 1 to 4 of 4
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default JButtons appear first AFTER rollover!

    Hello.
    I got this game that should be done in a few days and I got big problems.
    One of it is that the jbuttons in my menu does not show until mouseover!

    This is my class, I draw a simple image as background in the paint method:

    PHP Code:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    
    public class StartScreen extends JPanel{
    
    	public StartScreen(){
    		setPreferredSize(new Dimension(1000,700));
    		setLayout(new GridBagLayout());
    		//setBackground(new Color(164,235,255));
    		addButtons();
    	}
    	
    	@Override
    	public void paint(Graphics g){
    		g.drawImage(ImageLibary.Startscreen,0,0,null);
    	}
    
    	private void addButtons(){
    		GridBagConstraints c = new GridBagConstraints();
    		c.weightx = 0;
    		c.anchor = GridBagConstraints.CENTER;
    		c.insets = new Insets(10,0,0,0);
    
    		JButton start = new JButton("Start");
    		start.setPreferredSize(new Dimension (250,40));
    		add(start,c);
    		++c.gridy;
    		++c.gridy;
    
    		JButton players = new JButton("Players");
    		players.setPreferredSize(new Dimension (250,40));
    		add(players,c);
    		++c.gridy;
    
    		JButton quit = new JButton("Quit");
    		quit.setPreferredSize(new Dimension (250,40));
    		add(quit,c);
    		
    		validate();
    
    	}
    
    }

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

    Default

    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Don't override paint(...), override paintComponent(...)

    db

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Tyvm!
    Would never tought of that myself
    because I though jpanel doesnt have paitnComponent :D

    THANKS ALOT! :D

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

    Default

    Don't guess, just read the API and the tutorials.

    And you're welcome.

    db

Similar Threads

  1. Please help!JButtons
    By fourpixel in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2010, 01:48 PM
  2. Help with JButtons...
    By ashton in forum New To Java
    Replies: 8
    Last Post: 01-26-2009, 09:38 AM
  3. JButtons
    By jadaleus in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 02:49 AM
  4. 2D Array of JButtons
    By stevemcc in forum AWT / Swing
    Replies: 1
    Last Post: 02-16-2008, 11:42 PM
  5. JButtons
    By fgasimzade in forum SWT / JFace
    Replies: 1
    Last Post: 12-25-2007, 05:39 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
  •