When i go down and then return up, the button disappears. I don't know why..Is there any advice on this? I tried search in google/stackoverflow but I have not found answer. Anyway I don't have any ideas for this question, I tried everything
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
public class GenerateExam extends JFrame {
private JPanel contentPane;
private JButton button;
public GenerateExam() {
setTitle("Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0, 0, 800, 600);
button = new JButton("Click me!");
button.setBounds(50, 100, 100, 200);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
contentPane.add(button);
setContentPane(contentPane);
JPanel container = new JPanel();
JScrollPane jsp = new JScrollPane(container);
jsp.getVerticalScrollBar().setUnitIncrement(16);
container.setPreferredSize(new Dimension(750, 4000));
container.setLayout(null);
getContentPane().add(jsp);
centerFrame();
}
private void centerFrame() {
Dimension windowSize = getSize();
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
Point centerPoint = g.getCenterPoint();
int dx = centerPoint.x - windowSize.width / 2;
int dy = centerPoint.y - windowSize.height / 2;
setLocation(dx, dy);
}
public static void main(String[] args) {
GenerateExam exam = new GenerateExam();
exam.setVisible(true);
}
}