例如,我有两个单选按钮,我想在它们周围加一个边框,以便 UI 看起来更清晰?尝试搜索但没有找到任何有用的东西。 谢谢!
最佳答案
下面将在您的单选按钮周围创建一个边框。您可以创建不同类型的边框,查看 BorderFactory描述不同边界的API
JRadioButton yesButton = new JRadioButton("Yes", true);
JRadioButton noButton = new JRadioButton("No", false);
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(yesButton);
bgroup.add(noButton);
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(2, 1));
radioPanel.add(yesButton);
radioPanel.add(noButton);
radioPanel.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "BorderTitle"));
关于java - 使用GroupLayout时如何给组件添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16441011/