你能帮助我理解为什么在dataInputPanel
中没有填充(红色边框)吗?
目标:在dataInputPanel
中的顶部、右侧、底部和左侧有10个填充
错误:没有错误。就是不管用
主要:
public class Main {
public static void main(String[] args) {
JFrame win = new JFrame();
win.setTitle("Lord of the Rings - Battle Simulator");
win.setSize(500, 600);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setLayout(new GridLayout(2, 1));
win.setResizable(false);
//-------------
JPanel dataInputPanel = new JPanel();
dataInputPanel.setLayout(new GridLayout(1, 2, 10, 0));
//dataInputPanel.setBackground(Color.RED);
dataInputPanel.setBorder(new LineBorder(Color.RED, 4, true));
JPanel battleOutupPanel = new JPanel();
//battleOutupPanel.setBackground(Color.GREEN);
battleOutupPanel.setBorder(new LineBorder(Color.GREEN, 4, true));
//-------------------------------------
int paddingSize = 50;
Insets paddingInsets = new Insets(paddingSize, paddingSize, paddingSize, paddingSize);
// Heroes Data Input Panel - dataInputPanel GridBagLayout 1 row, 2 columns
JPanel heroesDataInputPanel = new JPanel();
//heroesDataInputPanel.setBackground(Color.YELLOW);
heroesDataInputPanel.setBorder(new LineBorder(Color.YELLOW, 4, true));
GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.gridx = 0;
gbc1.gridy = 0;
gbc1.insets = paddingInsets;
dataInputPanel.add(heroesDataInputPanel, gbc1);
// Beasts Data Input Panel - dataInputPanel - GridBagLayout 1 row, 2 columns
JPanel beastsDataInputPanel = new JPanel();
//beastsDataInputPanel.setBackground(Color.ORANGE);
beastsDataInputPanel.setBorder(new LineBorder(Color.ORANGE, 4, true));
GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.gridx = 1;
gbc2.gridy = 0;
gbc2.insets = paddingInsets;
dataInputPanel.add(beastsDataInputPanel, gbc2);
//-------------
win.add(dataInputPanel);
win.add(battleOutupPanel);
win.setVisible(true);
}
}
赢:
public class Win extends JFrame {
}
Pnl:
public class Pnl extends JPanel {
}
谢谢你!
1条答案
按热度按时间xnifntxz1#
您真的需要了解一下How to use borders-并重点关注
CompoundBorder