正如标题所说,我想要实现的是使用 JOptionPane 弹出一条选项消息,以便将问题和按钮放在同一行。我正在阅读以下教程,但似乎相当困难:
- How to Make Dialogs
- How to Make Dialogs Java
- Java Swing 权威指南
从某种意义上说,这个想法是具有以下确认消息布局:
<小时/>这些产品将从数据库中删除。
您确定要执行它吗? |是| |否|
<小时/>其中 YES 和 NO 应该是按钮。 (文字不是真实的文字,只是为了表达信息的味道)。
欢迎任何评论或提示。
提前非常感谢。
最佳答案
试试这个
JOptionPane.showConfirmDialog(null,
getCustomPanel(), // this will return a Panel design on your Own
"JOptionPane Example : ",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
//and your Custom Panel
private JPanel getCustomPanel() {
JPanel panel = new JPanel();
JLabel label = new JLabel("Text Message:");
panel.setLayout(null);
JButton okbtn=new JButton("ok");
label.setBounds(10,20,200,40); //x,y,width,height
okbtn.setBounds(220,20,80,40); //x,y,width,height
panel.add(label);
panel.add(okbtn);
return panel;
}
关于java - JOptionPane:文本消息和按钮在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689184/