Again - the problem - I dont have access to the JFrame- only to the panel.
I look several times on the scrollpane toturial in "sun" .
I control only the frame - other part of the program, which I cannot change or modify , add the panel to the frame. It is not that simple.
|
Code:
|
public static void main(String[] args) {
JFrame frame = new JFrame();
// I cant access JFrame.
//from here my program starts
JPanel panel = new JPanel(); //
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
for(int i = 0; i < 10; i++) {
panel.add(new JButton("JButton"));
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(panel));
frame.setSize(200,200);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
} |