Java 使用GroupLayout时如何向组件添加边框?
例如,我有两个单选按钮,我希望它们周围有一个边框,以便UI看起来更清晰?尝试搜索,但没有找到任何有用的内容。Java 使用GroupLayout时如何向组件添加边框?,java,swing,border,grouplayout,Java,Swing,Border,Grouplayout,例如,我有两个单选按钮,我希望它们周围有一个边框,以便UI看起来更清晰?尝试搜索,但没有找到任何有用的内容。 谢谢 下面将在单选按钮周围创建边框。您可以创建不同类型的边框,请检查API以获取有关不同边框的说明 JRadioButton yesButton = new JRadioButton("Yes", true); JRadioButton noButton = new JRadioButton("No", false); ButtonGroup bgroup = new But
谢谢 下面将在单选按钮周围创建边框。您可以创建不同类型的边框,请检查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"));
下面将在单选按钮周围创建边框。您可以创建不同类型的边框,请检查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"));
创建一个面板,将这些单选按钮放在该面板中。。并在面板周围创建边框
创建一个面板,将这些单选按钮放在该面板中。。并在面板周围创建边框
我希望有另一种方法,不使用面板,哦,好吧,谢谢。这是
JComponent
API中推荐的方法,我希望有另一种方法,不使用面板,哦,好吧,谢谢。这是JComponent
API中推荐的方法,