初始化主 GUI 时可见 JProgressBar

发布于 2024-11-28 07:00:01 字数 1105 浏览 0 评论 0原文

我正在为我正在进行的项目构建一个相当复杂的 GUI。重要的是,它包含(除其他外)一个 JTabbedPane,其中包含 12 个以上复杂 GUI 组件的窗格。

我想做的是在实例化这些窗格时显示 JProgressBar(创建和配置;执行除实际显示之外的所有操作)。实际上,我希望得到类似于 Eclipse 初始屏幕的最终结果:

在此处输入图像描述

这里是(更新为包括 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();
}

如果这是不可能的,或者我只是做错了,请告诉我。我环顾四周,看到了一些关于 Threading/SwingWorker 的提及,但是在弄乱了它和 Observer/Observable 的东西(诚然只有一点)之后,我仍然无法弄清楚。

I'm building a fairly complicated GUI for a project I'm working on. Importantly, it contains (among other things) a JTabbedPane with 12+ panes of complex GUI components.

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). Actually, I'm hoping for an end result similar to the Eclipse splash screen:

enter image description here

Here is (updated to include SplashScreen) pseudo-code for what I'm trying to do:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2024-12-05 07:00:01

要获得类似于 Eclipse 启动画面的内容,请参阅 java.awt.SplashScreen。一旦图像出现在屏幕上,就可以调用 SplashScreen.createGraphics() 来获取..

..用于启动屏幕覆盖图像的图形上下文(作为 Graphics2D 对象),它允许您在启动屏幕上进行绘制。

在其上绘制进度条。

To get something similar to the Eclipse splash, see java.awt.SplashScreen. Once the image is on-screen, it is possible to call SplashScreen.createGraphics() to get..

..a graphics context (as a Graphics2D object) for the splash screen overlay image, which allows you to draw over the splash screen.

Draw the progress bar on top of that.

佼人 2024-12-05 07:00:01

假设在 EDT(事件调度线程)中调用 setup(),该代码将起作用。

要调用 EDT 中的方法,请执行以下操作:

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

Assuming that setup() is being called in the EDT (Event Dispatch Thread), that code will work.

To invoke a method in the EDT do:

    SwingUtilities.invokeLater(new Thread() {
        @Override
        public void run() {
            setup();
        }
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文