初始化主 GUI 时可见 JProgressBar
我正在为我正在进行的项目构建一个相当复杂的 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获得类似于 Eclipse 启动画面的内容,请参阅 java.awt.SplashScreen。一旦图像出现在屏幕上,就可以调用 SplashScreen.createGraphics() 来获取..
在其上绘制进度条。
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..Draw the progress bar on top of that.
假设在 EDT(事件调度线程)中调用 setup(),该代码将起作用。
要调用 EDT 中的方法,请执行以下操作:
Assuming that setup() is being called in the EDT (Event Dispatch Thread), that code will work.
To invoke a method in the EDT do: