How can I set the size of JButton in an Applet?
I have an applet and I want to add a jbutton. The problem is the button is too big, I already used the setSize() method but still it doesn't work. Perhaps the setting of setSize could might be wrong.
could someone got an idea about this problem?
Thanks...
private JButton newGame = new JButton("New Game");
private JButton players = new JButton("Players");
private JButton quit = new JButton("Quit");
public void init()
{
Container content = getContentPane();
content.setLayout(new BorderLayout());
mainPanel = new JPanel();
getContentPane().add(mainPanel);
setVisible(true);
setSize(400, 400);
content.add(newGame);
content.add(play开发者_运维问答ers);
content.add(quit);
}
Please check the layout manager you are using for your container (panel, frame, applet..). This plays a major role in defining the size & position of components (like JButton
).
See also in the Java Tutorial for more details:
- Using Layout Managers.
- The Laying Out Components Within a Container lesson.
Add JPanel into your applet and then add JButton to it
The tree code conception is
JApplet (GridLayout) <- JPanel (FlowLayout) <- JButton (setSize(new Dimension(x,y)))
Good Luck
精彩评论