选择在窗格与Swing文件 [英] Choosing a file in-pane with Swing

查看:111
本文介绍了选择在窗格与Swing文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写在Swing的GUI,我想要做一个文件选择是在主窗口中,看起来像下面的图片:

I'm writing a GUI in Swing where I want to do a file chooser that is in the main window, looking something like the image below:

而似乎有关于如何编写一个弹出文件选择相当多的教程,我没有看到有关如何这种类型的选择器可能会在摆动来完成的信息。

while there seem to be quite a few tutorials on how to write a popup file chooser, i don't see much information on how this type of chooser might be accomplished in swing.

也对不起,如果这已问过,我做搜索周围,wan't能找到别的好一点..

also sorry if this has been asked before, i did a good bit of searching around and wan't able to find anything else..

推荐答案

的JFileChooser 的实际扩展JComponent的,所以您可以像使用任何其他组件。下面是一个例子的两个的在窗格文件挑肥拣瘦:

JFileChooser actually extends JComponent, so you can use like any other component. Here is an example with two in-pane file choosers:

public class TestInPaneChoosers {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                buildFrame();
            }
        });
    }

    private static void buildFrame() {
        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        f.setLayout(new FlowLayout());

        f.add(new JFileChooser());
        f.add(new JFileChooser());

        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}

这篇关于选择在窗格与Swing文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆