当前位置: 代码迷 >> Java相关 >> [求助]Swing如何调用通用对话框
  详细解决方案

[求助]Swing如何调用通用对话框

热度:136   发布时间:2007-01-24 19:07:00.0
[求助]Swing如何调用通用对话框


///以下是关键部分代码,运行良好,就是不会调"打开通用对话框"
class MainPanel extends JPanel
{
public MainPanel()
{
JLabel lblIn = new JLabel("源文件:");
lblIn.setBounds(30, 30, 50, 20);
JTextArea txtInFile = new JTextArea();
txtInFile.setBounds(80,30,100,20);

JButton btnSelect = new JButton("选择文件");
btnSelect.setBounds(190, 30, 80, 20);
JFileChooser open = new JFileChooser();
btnSelect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((JButton)e.getSource()).setLabel("已选"); //这里我想弹出一个打开文件的通用对话框应该怎么调用?
System.out.println("打开文件"); //调用这方法JFileChooser.showOpenDialog(this)不对..

}
}
);

JLabel lblOut = new JLabel("复制到:");
lblOut.setBounds(30, 60, 50, 20);
JTextArea txtOutFile = new JTextArea();
txtOutFile.setBounds(80,60,100,20);

JButton btnCopy = new JButton("开始复制");
btnCopy.setBounds(60, 90, 90, 20);



add(lblIn);
add(txtInFile);
add(btnSelect);
add(lblOut);
add(txtOutFile);
add(btnCopy);
}

搜索更多相关的解决方案: 对话框  Swing  new  setBounds  

----------------解决方案--------------------------------------------------------
传入null

JOptionPane.showMessageDialog(null,"这是消息");
----------------解决方案--------------------------------------------------------

也可以传入MainPanel.this来表示外部的引用


----------------解决方案--------------------------------------------------------
谢谢,冰封..
----------------解决方案--------------------------------------------------------