JOptionPane 组件放置
JOptionPane component placement
我有一个 JOptionPane 对话框,看起来像这样。
我希望复选框像这样位于图标下方。
可以使用 JOptionPane 还是我必须创建自己的对话框?
这是第一张图片的代码。
public static void main(String[] args) {
Box box = Box.createVerticalBox();
box.add(new JLabel("TEXT"));
box.add(new JCheckBox("Check box text"));
int result = JOptionPane.showConfirmDialog(null,
box,
"TITLE",
JOptionPane.YES_NO_OPTION);
}
使用 PLAIN_MESSAGE 然后在面板中显示图标:
public static void main(String[] args) throws Exception
{
JPanel first = new JPanel( new FlowLayout( FlowLayout.LEFT) );
first.add( new JLabel( UIManager.getIcon("OptionPane.questionIcon" ) ) );
first.add(new JLabel("TEXT"));
JPanel box = new JPanel( new GridLayout(0, 1) );
box.add(first);
box.add(new JCheckBox("Check box text"));
int result = JOptionPane.showConfirmDialog(null,
box,
"TITLE",
JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE
);
}
我有一个 JOptionPane 对话框,看起来像这样。
我希望复选框像这样位于图标下方。
可以使用 JOptionPane 还是我必须创建自己的对话框?
这是第一张图片的代码。
public static void main(String[] args) {
Box box = Box.createVerticalBox();
box.add(new JLabel("TEXT"));
box.add(new JCheckBox("Check box text"));
int result = JOptionPane.showConfirmDialog(null,
box,
"TITLE",
JOptionPane.YES_NO_OPTION);
}
使用 PLAIN_MESSAGE 然后在面板中显示图标:
public static void main(String[] args) throws Exception
{
JPanel first = new JPanel( new FlowLayout( FlowLayout.LEFT) );
first.add( new JLabel( UIManager.getIcon("OptionPane.questionIcon" ) ) );
first.add(new JLabel("TEXT"));
JPanel box = new JPanel( new GridLayout(0, 1) );
box.add(first);
box.add(new JCheckBox("Check box text"));
int result = JOptionPane.showConfirmDialog(null,
box,
"TITLE",
JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE
);
}