Jav*_*107 9 java swing jframe insets
有没有办法设置一个JFrame?我试过了
frame.getContentPane().getInsets().set(10, 10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
和
frame.getInsets().set(10, 10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
但它们似乎都没有用.
Mar*_*rra 22
JPanel contentPanel = new JPanel();
Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);
contentPanel.setBorder(padding);
yourFrame.setContentPane(contentPanel);
Run Code Online (Sandbox Code Playgroud)
所以基本上,contentPanel是你的框架的主要容器.
您必须创建一个 LayOutConstraint 对象并设置其 Insets。就像下面的示例一样,我使用了 GridBagLayout() 并使用了 GridBagConstraint() 对象。
GridBagConstraints c = new GridBagConstraints();
JPanel panel = new JPanel(new GridBagLayout());
c.insets = new Insets(5, 5, 5, 5); // top, left, bottom, right
c.anchor = GridBagConstraints.LINE_END;
// Row 1
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.LINE_START;
panel.add(isAlgoEnabledLabel, c);
Run Code Online (Sandbox Code Playgroud)