我目前正在开发一个java应用程序。
我想显示一个新的窗口,其中包含一个文本区和一个按钮。
你有什么想法吗?
嗯,已经有一段时间了,但从我记得的情况来看......
如果你想要一个自定义的窗口,你可以只做一个新的框架,让它像主窗口那样显示出来。
Java也有一个很好的对话框库,你可以在这里查看:
如何制作对话框 。
这可能会给你带来你想要的功能,但却少了很多麻烦。
Object[] possibilities = {"ham", "spam", "yam"};
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"ham");
//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
setLabel("Green eggs and... " + s + "!");
return;
}
//If you're here, the return value was null/empty.
setLabel("Come on, finish the sentence!");
如果你不在乎限制用户的选择,你可以使用showInputDialog方法的一种形式,该方法需要较少的参数,或者为对象阵列指定null。在Java的外观中,用null代替可能性的结果是一个有文本字段的对话框,看起来像这样:
看看Swing Dialogs(主要集中在JOptionPane,正如@mcfinnigan提到的)。