Reputation: 51
I am learning on how to make an applet. I have a frame which contains the applet. Within the applet, there are 4 different panels: One main panel (with BorderLayout) and 3 sub-panels within the main one()-one to the North, one to the South and one to Center). Whenever I launch the applet, the main frame size is very small. I tried to change it using setSize() but it doesnt work. I then tried using setPreferedSize() and pack() from other posts, but it doesn't work for me. Here is my code:
BounceBallApp applet = new BounceBallApp();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("BounceBallApp");
frame.add(applet, BorderLayout.CENTER);
frame.setPreferredSize(new Dimension(1000, 1000));
frame.setLocationByPlatform(true);
frame.pack();
frame.setVisible(true);
Upvotes: 0
Views: 351
Reputation: 16214
Try using Component#setMinimumSize(...)
this won't allow for any layout manager, to violate this minimum size.
Upvotes: 0
Reputation: 347184
Well, there's your problem...
frame.setPreferredSize(new Dimension(1000, 1000));
frame.setLocationByPlatform(true);
frame.pack(); <-- This is you're problem, or is it...
pack
will you use the layout managers preferred size to "pack" the frame so you don't have to guess...
From the Java Docs...
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. The resulting width and height of the window are automatically enlarged if either of dimensions is less than the minimum size as specified by the previous call to the setMinimumSize method.
If the window and/or its owner are not displayable yet, both of them are made displayable before calculating the preferred size. The Window is validated after its size is being calculated.
Also...I can't begin to wounder why you want to mix two top level containers in this way, but I'd really encourage you not to...
Upvotes: 1