JOptionPane:在同一行中发送消息和按钮

JOptionPane: texts message and buttons in the same line

正如标题所说,我想要实现的是使用 JOptionPane 弹出一条选项消息,以便将问题和按钮放在同一行。我正在阅读以下教程,但似乎很难:

从某种意义上说,这个想法是具有以下确认消息布局:


产品将从数据库中删除。

您确定要执行吗? |是| |否|


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;
    }