[英]Fixing the size of a jButton with full screen and GridBagConstrains
I am trying to have my jButton really small. 我正在尝试使我的jButton很小。 It works if I change the margins (the 250 in the example).
如果更改边距(示例中为250),它会起作用。 But this will not work with variable screen size.
但这不适用于可变的屏幕尺寸。 Any other method?
还有其他方法吗?
startButton = new JButton("Start");
//this is not taking:
startButton.setPreferredSize(new Dimension(50, 40));
contentPanel.add(startButton, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST,
GridBagConstraints.HORIZONTAL, new Insets(150, 250, 0, 250), 0, 0));
As far as I understand the 250 are left and right margin. 据我了解,这250个左右边距。 Of course by changing these the size changes.
当然,通过改变这些尺寸可以改变。 But since it's full screen this is not a robust way to do it.
但是由于它是全屏的,所以这不是一种健壮的方法。 Any ideas on how to make the button minimal size and then just center it?
关于如何使按钮最小化然后居中的想法?
I was able to resize the button with: 我能够通过以下方式调整按钮的大小:
contentPanel.add(buttonsPanel, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.HORIZONTAL, new Insets(100, 100, 0, 100), 0, 0));
startButton.setPreferredSize(new Dimension(100, 40));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.