【问题标题】:Removing the cancel button of a window using JOptionPane [duplicate]使用 JOptionPane 删除窗口的取消按钮 [重复]
【发布时间】:2013-09-22 22:07:13
【问题描述】:

我已经尝试过其他主题,所以请不要将我发送到其他主题/教程,因为我还没有设法理解它并且我已经尝试过。如果您没有帮助,请不要回复。

I would like to change this code to display only "OK" and delete the cancel button.

Object contestacion5 = JOptionPane.showInputDialog(null, "#5 Que describe mejor a la Norteña?", "Examen Tijuanas PR", //3
        JOptionPane.DEFAULT_OPTION, null,
        new Object[] {"Ensalada de espinacas, tomates, zetas, cebolla, tocineta, aguacate, queso de hoja y tiras de maiz crujientes en vinagreta de la casa.",
        "Lechuga romana servida con tomate, cebolla, maiz, aguacate, queso de hoja y tiritas de maiz crujientes acompañado de su seleccion de filetes de pollo de res.", 
        "Ensalada vegetariana de nopales, tomates, cebolla, lechuga romana, queso de hoja, aguacate, y aderezo especial de la casa." }, null);

这是图片,我想要它,但没有取消按钮,谢谢!

我尝试过这样做:Is there a way to only have the OK button in a JOptionPane showInputDialog (and no CANCEL button)?

这就是它显示的内容:

【问题讨论】:

  • 在您显示的链接中分享您用来尝试该方法的代码。这非常简单,出了什么问题?
  • 另外:请不要转发您的问题。改用旧的;这个将被标记为重复。 stackoverflow.com/questions/18946681/…
  • -1 so please do not send me to another topic/tutorial because I have not managed to understand it and I HAVE TRIED. If you are not helping please do not reply. - 我向您指出的教程有一个工作示例。由于您的代码不起作用,您显然没有阅读教程或从工作示例开始。我们不是来给你喂食和写代码的。强迫您阅读教程并尝试示例确实对您有所帮助。如果您不学习阅读和遵循示例,就无法编程。

标签: java swing joptionpane


【解决方案1】:

使用linked 的方法,这样您就可以解决错误。希望您确实阅读本教程。

JPanel panel = new JPanel(new GridLayout(2, 1)); // layout sets combobox under label
JLabel label = new JLabel("#5 Que describe mejor a la Norteña?");
JComboBox selection = new JComboBox(new String[]{"Ensalada de espinacas, tomates, zetas, cebolla, tocineta, aguacate, queso de hoja y tiras de maiz crujientes en vinagreta de la casa.",
            "Lechuga romana servida con tomate, cebolla, maiz, aguacate, queso de hoja y tiritas de maiz crujientes acompañado de su seleccion de filetes de pollo de res.",
            "Ensalada vegetariana de nopales, tomates, cebolla, lechuga romana, queso de hoja, aguacate, y aderezo especial de la casa."});
String[] options = {"OK"};
panel.add(label);
panel.add(selection);
JOptionPane.showOptionDialog(null, panel, "Examen Tijuanas PR",
     JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 
     null, options, options[0]);

结果:

【讨论】:

  • 谢谢,我现在需要从 JComboBox 更改为 String,以便在 if/else 上使用累加器。这是错误:不兼容的操作数类型 JComboBox 和 String
  • @Emmanuel Urias 很抱歉,我不明白您在说什么,请与 SSCE 一起编辑新问题的问题,以便我可以帮助您。
猜你喜欢
  • 1970-01-01
  • 2011-12-31
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-02
  • 2012-07-14
  • 2012-02-01
相关资源
最近更新 更多