简体   繁体   English

JOptionPane如何调用自定义按钮

[英]JOptionPane how to call custom buttons

Hey I made a custom JOptionPane that shows multiple custom buttons 嘿,我制作了一个自定义JOptionPane,它显示了多个自定义按钮

String [] codeVlakken = {"Kleur 1", "Kleur 2", "Kleur 3", "Kleur 4" };
JOptionPane.showOptionDialog(null, code , "Cheat menu", JOptionPane.YES_NO_OPTION,
    JOptionPane.PLAIN_MESSAGE, null, codeVlakken, "" );

So in the first line I defined what is in my array and on the second line at the end I placed my array name so it will fill it up with my custom named buttons. 因此,在第一行中,我定义了数组中的内容,在第二行中,最后放置了数组名,以便它将其与自定义命名按钮一起填充。

Now I want to give each custom button a different color, how can I call "Kleur 1" for example from it? 现在,我想为每个自定义按钮赋予不同的颜色,例如,如何从中调用“ Kleur 1”?

Thanks in advance 提前致谢

The options parameter takes a type of Object[] options参数采用一种Object[]

Instead of using an array of String s, try using an array of JButton s. 代替使用String数组,请尝试使用JButton数组。

This would allow you to create and define the properties of buttons before you add then to the dialog 这将允许您在添加然后添加到对话框之前创建和定义按钮的属性。

Updated 更新

JButton [] codeVlakken = {JButton("Kleur 1")};
JOptionPane.showOptionDialog(null, code , "Cheat menu", JOptionPane.YES_NO_OPTION,
    JOptionPane.PLAIN_MESSAGE, null, codeVlakken, "" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM