简体   繁体   English

在初始化主GUI时可见JProgressBar

[英]Visible JProgressBar while initializing main GUI

I'm building a fairly complicated GUI for a project I'm working on. 我正在为我正在开发的项目构建一个相当复杂的GUI。 Importantly, it contains (among other things) a JTabbedPane with 12+ panes of complex GUI components. 重要的是,它包含(除此之外)具有12个以上复杂GUI组件窗格的JTabbedPane

What I'm trying to do is display a JProgressBar when I'm instantiating these panes (creating and configuring; doing everything short of actually displaying). 我正在尝试做的是在我实例化这些窗格时创建一个JProgressBar (创建和配置;做所有事情都不能实际显示)。 Actually, I'm hoping for an end result similar to the Eclipse splash screen: 实际上,我希望得到类似Eclipse启动画面的最终结果:

在此输入图像描述

Here is (updated to include SplashScreen) pseudo-code for what I'm trying to do: 这是(更新为包含SplashScreen)伪代码,我正在尝试做什么:

ProgramManager:
private setupGUI() {
    mainGUI = new MainGUI(); // only instantiates internal JFrame field
    mainGUI.setup();
}

MainGUI:
public void setup() {
    //create and configure progress bar
    final SplashScreen ss = SplashScreen.getSplashScreen();
    JProgressBar jpb = new JProgressBar(){
        Graphics g = ss.createGraphics();
        @Override
        public void paint(Graphics pG) {
            // TODO Auto-generated method stub
            super.paint(g);
        }
    };
    jpb.setValue(0);        
    setup1stTab();
    //update Progress
    setup2ndTab();
    //update progress
    etc....
    ss.close();
}

Please let me know if this is just not possible, or if I'm simply going about it wrong. 如果这是不可能的,或者如果我只是错了,请告诉我。 I've looked around and seen some mention of Threading/ SwingWorker , but after messing around with that and the Observer/Observable stuff (admittedly only a little), I still can't figure it out. 我环顾四周,看到有人提到了Threading / SwingWorker ,但是在搞乱了那个和Observer / Observable的东西后(不可否认只是一点点),我仍然无法弄明白。

To get something similar to the Eclipse splash, see java.awt.SplashScreen . 要获得类似于Eclipse splash的内容,请参阅java.awt.SplashScreen Once the image is on-screen, it is possible to call SplashScreen.createGraphics() to get.. 一旦图像在屏幕上,就可以调用SplashScreen.createGraphics()来获取..

..a graphics context (as a Graphics2D object) for the splash screen overlay image, which allows you to draw over the splash screen. ..a图形上下文(作为Graphics2D对象)用于初始屏幕叠加图像,允许您在初始屏幕上绘图。

Draw the progress bar on top of that. 在上面绘制进度条。

Assuming that setup() is being called in the EDT (Event Dispatch Thread), that code will work. 假设在EDT(事件调度线程)中调用setup(),该代码将起作用。

To invoke a method in the EDT do: 要在EDT中调用方法,请执行以下操作:

    SwingUtilities.invokeLater(new Thread() {
        @Override
        public void run() {
            setup();
        }
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM