Results 1 to 5 of 5
- 12-04-2011, 08:25 AM #1
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
someone who has an idea what i did wrong? :o :(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; } }
all help is appreciated. ^^
grtz lil
- 12-04-2011, 12:32 PM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Re: JButton doesnt show unless you move mouse over it
try to call setVisible() after initGUI().
- 12-04-2011, 02:02 PM #3
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-05-2011, 07:37 PM #4
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
-
Re: JButton doesnt show unless you move mouse over it
Yes, layouts are recommended, and the more complex your GUI, the more it needs to use layouts.
Similar Threads
-
Applet doesnt start or it doesnt show
By 3dprogger in forum Java AppletsReplies: 2Last Post: 01-07-2011, 07:03 PM -
Last JLabel I add to JPanel doesnt show up
By Ambergahill in forum New To JavaReplies: 5Last Post: 11-15-2010, 10:37 PM -
combobox doesnt show!
By LennyKosmos in forum New To JavaReplies: 2Last Post: 10-26-2010, 08:07 PM -
doesnt show exact size
By clydedoris in forum NetBeansReplies: 3Last Post: 07-13-2010, 06:59 AM -
JTable doesnt show columun names!
By phil128 in forum AWT / SwingReplies: 3Last Post: 03-08-2009, 10:39 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks