使用全屏和 GridBagConstrains 修复 jButton 的大小
Fixing the size of a jButton with full screen and GridBagConstrains
我想让我的 jButton 非常小。如果我更改边距(示例中的 250),它会起作用。但这不适用于可变屏幕尺寸。还有其他方法吗?
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));
据我了解250是左右边距。当然,通过更改这些尺寸会发生变化。但是因为它是全屏的,所以这不是一个可靠的方法。关于如何使按钮尺寸最小然后将其居中的任何想法?
我可以通过以下方式调整按钮的大小:
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));
我想让我的 jButton 非常小。如果我更改边距(示例中的 250),它会起作用。但这不适用于可变屏幕尺寸。还有其他方法吗?
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));
据我了解250是左右边距。当然,通过更改这些尺寸会发生变化。但是因为它是全屏的,所以这不是一个可靠的方法。关于如何使按钮尺寸最小然后将其居中的任何想法?
我可以通过以下方式调整按钮的大小:
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));