Disappearing Buttons [message #1859233] |
Sun, 21 May 2023 20:37  |
Eclipse User |
|
|
|
I am having issues with jbuttons being missing until i mouse over them on my jframe here is my jframe code
JFrame frame = new JFrame();
frame.setForeground(Color.WHITE);
frame.getContentPane().setForeground(Color.BLACK);
frame.setBounds(100, 100, 357, 539);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setVisible(true);
if you have any questions thanks in aadvance
here is my button code jusy incase
JButton btn2 = new JButton("2");
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String number = textField.getText() + btn2.getText();
textField.setText(number);
}
});
btn2.setFont(new Font("Tahoma", Font.BOLD, 23));
btn2.setBounds(139, 398, 64, 50);
frame.getContentPane().add(btn2);
|
|
|
|
|
|
Re: Disappearing Buttons [message #1859260 is a reply to message #1859250] |
Wed, 24 May 2023 09:33  |
Eclipse User |
|
|
|
The JButton and JFrame code looks okay, but there could be a few reasons why the buttons aren't showing up until you hover over them.
- Painting Issues: Sometimes, Java Swing components don't show up until they're interacted with. This could be due to issues with how they're drawn on screen.
- Layout Management: You're using null layout for your JFrame, which can lead to issues if not handled right.
- Thread Issues: GUI updates in Swing need to happen on the Event Dispatch Thread (EDT). If the code adding your button isn't on this thread, it could cause problems.
|
|
|
Powered by
FUDForum. Page generated in 0.07735 seconds