Answer the question
In order to leave comments, you need to log in
Why does the button only show up on hover?
The button is displayed only when hovering over. Why is this and how can I solve this problem? I want my buttons to show up right away.
public class Room extends JPanel{
Image back = new ImageIcon("res/images/interior1.jpg").getImage();
private JButton toLeft = new JButton(new ImageIcon("res/images/arrowLeftUnpressed.png"));
private JButton toRight = new JButton(new ImageIcon("res/images/arrowRightUnpressed.png"));
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(back, 0, 0, 1920, 1080, null);
}
public Room() {
setLayout(null);
add(toLeft);
toLeft.setBounds(50, 470, 170, 170);
add(toRight);
toRight.setBounds(1700, 470, 170, 170);
}
}
public class Display {
public Display() {
JFrame frame = new JFrame("MindLoop");
frame.getContentPane().add(new Room());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setUndecorated(true);
frame.setVisible(true);
}
public static void main(String[] args) {
new Display();
}
}
Answer the question
In order to leave comments, you need to log in
Greetings. You don't need to override the top-level container's paint, instead override the paintComponent method, call the super constructor in it, and draw your button.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question