每当我将jbutton添加到我的容器中时,它真的很大。我认为使用label.setBounds()函数会起作用,但它没有
public Liability_Calculator(String s)
{
super(s);
setSize(325,200);
Color customColor = Color.WHITE;
c = getContentPane();
c.setLayout(new BorderLayout());
//the button
ok = new JButton("OK");
//ok.setSize(50, 50);
//HERE IS WHERE I TRY AND RESIZE!
ok.setBounds(30,30,50,50);
c.add(ok, BorderLayout.SOUTH);
setVisible(true);
}
答案 0 :(得分:2)
建议:
例如,默认情况下,JPanel使用FlowLayout(FlowLayout.CENTER))
,您可以将ok JButton放入JPanel,然后将JPanel放入contentPane中,以利用它:
ok = new JButton("OK");
// ok.setBounds(30, 30, 50, 50);
JPanel southPanel = new JPanel();
southPanel.add(ok);
c.add(southPanel, BorderLayout.SOUTH);
这会将第一张图片更改为第二张图片: