Jua*_*ong 2 java swing joptionpane
String result = JOptionPane.showInputDialog(this, temp);
Run Code Online (Sandbox Code Playgroud)
result 值将是输入的值.
String result = JOptionPane.showInternalInputDialog(this, temp);
Run Code Online (Sandbox Code Playgroud)
result 即使您输入了一个字符串,该值也将为null.
temp是一个将包含在JOptionPane中的面板.此JOptionPane将显示在另一个自定义JOptioPane之上.
JOptionPane.showInternalInputDialog仅与JDesktopPane/ JInternalFrames 一起使用,其中this是JDesktopPane/ JInternalFrames实例.
final JDesktopPane desk = new JDesktopPane();
...
String s=JOptionPane.showInternalInputDialog(desk, "Enter Name");
Run Code Online (Sandbox Code Playgroud)
如果不与上述两个组件中的任何一个一起使用,它将不会产生正确的输出,实际上它会抛出一个运行时异常:
java.lang.RuntimeException:JOptionPane:parentComponent没有有效的父级
UPDATE
按您的意见在这里是如何添加一个例子JPanel来JDesktopPane和调用JOptionPane#showInternalInputDialog.重要的是我们需要打电话setBounds和打电话,setVisible就JPanel好像它JInternalFrame被添加到了JDesktopPane,除了我们当然要添加一个JPanel
JFrame frame = new JFrame("JInternalFrame Usage Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// A specialized layered pane to be used with JInternalFrames
jdpDesktop = new JDesktopPane() {
@Override
public Dimension getPreferredSize() {
return new Dimension(600, 600);
}
};
frame.setContentPane(jdpDesktop);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 600, 600);
jdpDesktop.add(panel);
frame.pack();
frame.setVisible(true);
panel.setVisible(true);
String result = JOptionPane.showInternalInputDialog(jdpDesktop, "h");
System.out.println(result);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4667 次 |
| 最近记录: |