-4

I have tried other topics, 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.

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

http://i.snag.gy/6nSlc.jpg

Here it is the picture, I want it exactly as this but without the Cancel button, thanks!

I have tried to do this way: Is there a way to only have the OK button in a JOptionPane showInputDialog (and no CANCEL button)?

and this is what it displays: http://i.snag.gy/eFoqN.jpg

Community
  • 1
  • 1
  • Share the code you have used to try the approach in the link you showed. It's extremely straightforward, what went wrong? – Jeroen Vannevel Sep 22 '13 at 22:09
  • 3
    Also: please don't repost your question. Improve your old one instead; this one will get flagged for duplication. http://stackoverflow.com/questions/18946681/i-would-like-to-change-this-code-to-display-only-ok-and-delete-the-cancel-butt – Jeroen Vannevel Sep 22 '13 at 22:16
  • 3
    -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.` - the tutorial I pointed you to has a working example. Since you code does not work you obviously did not read the tutorial or start with the working example. We are not here to spoon feed and write the code for you. Forcing you to read the tutorial and try the examples does help you. You can't program if you don't learn to read and follow examples. – camickr Sep 22 '13 at 22:25

1 Answers1

1

Using the approach you linked, so you can work on your errors. Hope you do read the tutorial though.

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]);

Result:

enter image description here

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
maryokhin
  • 1,058
  • 13
  • 20
  • thanks, I need to change now from JComboBox to String, to use a acumulator on a if/else. This is the error: Incompatible operand types JComboBox and String – Emmanuel Urias Sep 24 '13 at 01:33
  • @Emmanuel Urias I'm sorry, but I didn't understand what you are talking about, edit question with SSCE of new problem so I can try to help you. – maryokhin Sep 24 '13 at 09:01