Reputation: 2315
I am not sure how to fix this, I have several JPanels (used for drawing) inside a main JPanel using BoxLayout. The JPanels have a set minimum size and preferred size. The main JPanel only shows the 3 out of the five, as it is too small. I tried setting the size of the main JPanel pretty large and also tried adding a scroler but then nothing shows up.
Here is some code:
public static void main(String[] args) throws XMLStreamException, IOException {
JFrame frame = makeFrame(500, 500);
JPanel panel = new JPanel();
panel.setSize(1800, 1800);
JScrollPane scroller = new JScrollPane(panel);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
frame.add(scroller);
test1(panel);
}
public static JFrame makeFrame(int sizex, int sizey){
JFrame frame = new JFrame();
frame.setTitle("FDA");
frame.setSize(sizex, sizey);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
return frame;
}
test1
adds six JPanels with size 360x360 to panel
.
With the scrollbar I only see one of the JPanels, and no scrollbars appear.
Edit: I have to wait until all my calculations are done before I paint the main JPanel, that is why it wasn't displaying the last 3.
Upvotes: 1
Views: 763
Reputation: 109823
frame.setVisible(true);
is executed before its JComponents
are created and added (to this already visible JFrame)
please whats test1(panel);
Upvotes: 2