我在寫一個需要文件打開對話框的java程序。文件打開對話框並不困難,我希望能使用JFileChooser
。我的問題是,我想有一個雙窗格JFrame
(由2 JPanels
組成)。左側面板將具有JList
,右側面板將具有文件打開對話框。JFileChooser嵌入在JPanel中
當我使用JFileChooser.showOpenDialog()
這會打開所有其他窗口上方的對話框,這不是我想要的。有沒有辦法讓JFileChooser
(或其他文件選擇對話框)在JPanel
內顯示,而不是在上面彈出?
這是我試過的代碼,在這一點上它非常簡化。我只是試圖在此時將JFileChooser
嵌入到JPanel
中。
public class JFC extends JFrame{
public JFC()
{
setSize(800,600);
JPanel panel= new JPanel();
JFileChooser chooser = new JFileChooser();
panel.add(chooser);
setVisible(true);
chooser.showOpenDialog(null);
}
public static void main(String[] args)
{
JFC blah = new JFC();
}
}
我也打過電話chooser.showOpenDialog
與this
和panel
,但無濟於事。另外,我嘗試將JFileChooser
直接添加到框架。上面列出的兩種嘗試仍然在框架或面板前面彈出JFileChooser
(取決於我添加的JFileChooser
)。