2013-09-22 45 views
-4

我已經嘗試過其他主題,所以請不要將我發送給另一個主題/教程,因爲我沒有設法理解它並且我嘗試過。如果你不幫忙,請不要回復。使用JOptionPane刪除窗口的取消按鈕

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

這是圖片,我想這正是因爲這一點,但沒有取消按鈕,謝謝!

我試圖做這樣:Is there a way to only have the OK button in a JOptionPane showInputDialog (and no CANCEL button)?

,這就是它顯示:http://i.snag.gy/eFoqN.jpg

+0

分享您用來嘗試在你表現出的鏈接方法的代碼。這非常簡單,出了什麼問題? –

+3

另請參閱:請不要轉發您的問題。改善你的舊的;這個會被標記爲重複。 http://stackoverflow.com/questions/18946681/i-would-like-to-change-this-code-to-display-only-ok-and-delete-the-cancel-butt –

+3

-1'所以請做不要發送給我另一個主題/教程,因爲我沒有設法理解它並且我嘗試過。如果你不幫忙,請不要回復。「 - 我指出你的教程有一個實例。由於您的代碼不起作用,您顯然沒有閱讀教程或從實際示例開始。我們不是在這裏舀食物併爲你寫代碼。強迫你閱讀教程並嘗試這些例子對你有幫助。如果你不學習閱讀和遵循例子,你將無法編程。 – camickr

回答

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

Result (沒有足夠的信譽,爲圖像,從而鏈接到圖片)

enter image description here

+0

謝謝,我需要現在從JComboBox更改爲字符串,以在if/else上使用acumulator。 這是錯誤:不兼容的操作數類型JComboBox和字符串 –

+0

@Emmanuel Urias對不起,但我不明白你在說什麼,編輯問題與SSCE的新問題,所以我可以嘗試幫助你。 – maryokhin