I'm having some problems with a start up/splash window (see example
below).
I ant to use a border less window, therefore I'M not using JFrame for
that. With Jframe it works perfectly.
Questions:
1. how can I get rid of the flickering? setting setVisible at #2
instead of #1 will work, but then the user won't be able to see the
textoutput under the build up, hence not an option.
2. is there a way to get the desktopPane.getBounds().height at #3 if
setVisible
hasn't been run yet? (in such case it returns 0)
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class Test extends JFrame
{
static JFrame frm=null, frm1=null;
static JWindow win=null;
static JDesktopPane desktopPane = new JDesktopPane();
static JProgressBar pBar= new JProgressBar();
static JLabel text = new JLabel(" ");
static JTextArea ta = new JTextArea();
public static void main(String args[])
{
win = startUp();
sleepThread(500);
update("Building Desktop Pane...",1);
frm1 = new Test();
frm.setVisible(true); //#1
sleepThread(200);
update("Building Internal Frame 1 ...",2);
sleepThread(200);
JInternalFrame j1 = createInternalFrame1();
j1.setVisible(true); //#1
sleepThread(200);
update("Building Internal Frame 2 ...",3);
sleepThread(200);
JInternalFrame j2 = createInternalFrame2();
j2.setVisible(true); //#1
sleepThread(200);
update("Do some configuration...",4);
for(int i=0; i<20;i++)
ta.append("adjg"+ i + "rehgkjh\n");
sleepThread(1000);
//#2
//frm.setVisible(true);
//j1.setVisible(true);
//j2.setVisible(true);
update("Startup finished ...",3);
closeStartup();
sleepThread(5000);
closeStartup();
System.exit(0);
}//main
public static JWindow startUp()
{
JWindow window = new JWindow();
JPanel panel = new JPanel();
panel.setLayout(null);
JLabel lab[] = new JLabel [3];
lab[0] = new JLabel("Some");
lab[1] = new JLabel("start up");
lab[2] = new JLabel("Text");
int row=10;
for(int i=0;i<3;i++)
{
panel.add(lab[i]);
lab[i].setSize( lab[i].getPreferredSize() );
lab[i].setLocation( 10,row);
row = row + lab[i].getHeight()+2;
}
row = row +10;
panel.add(text);
text.setLocation( 10, row );
text.setSize( text.getPreferredSize() );
row = row + text.getHeight()+7;
pBar.setForeground(Color.blue);
pBar.setBorderPainted(false);
pBar.setValue(0);
pBar.setStringPainted(true);
panel.add(pBar);
pBar.setLocation( 10, row );
pBar.setSize( pBar.getPreferredSize() );
row=row+pBar.getHeight();
window.getContentPane().add(panel);
window.pack();
panel.setSize(200,row+10);
window.setSize(200,row+10);
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle frameDim = window.getBounds();
window.setLocation((screenDim.width - frameDim.width) / 2,
(screenDim.height - frameDim.height) / 2);
window.show();
window.toFront();
window.setVisible(true);
return window;
}//startUp
public static void update(String str, int n)
{
int p = 100 / 10 * n;
if(win!=null)
{
text.setText( str );
text.setSize( text.getPreferredSize() );
pBar.setValue(p);
pBar.setSize( pBar.getPreferredSize() );
win.toFront();
sleepThread(3);
}
}//pbupdate
public static void closeStartup()
{
if(win!=null)
{
win.setVisible(false);
win.dispose();
win=null;
}
}//closeStartup
public Test()
{
JMenuBar menubar = new JMenuBar();
JMenu fileMenu = new JMenu( "File");
menubar.add(fileMenu);
frm = new JFrame("Test");
Container contentPane = frm.getContentPane();
frm.setJMenuBar( menubar );
contentPane.setLayout(new BorderLayout() );
contentPane.add(desktopPane, BorderLayout.CENTER);
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
frm.setBounds(10,10,300,400);
frm.setLocation((screenDim.width - 300) / 2, (screenDim.height -
400) / 2);
frm.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}//Test
public static JInternalFrame createInternalFrame1()
{
JInternalFrame jif = new JInternalFrame( "JIF1", false, false,
false, false );
//int h = desktopPane.getBounds().height; //#3
int h=200;
jif.setBounds(0, 0, 100, h-20);
Container jifcp = jif.getContentPane();
jifcp.add(new JScrollPane(ta),BorderLayout.CENTER);
//jif.setVisible(true);
desktopPane.add(jif);
return jif;
}//createInternalFrame
public static JInternalFrame createInternalFrame2()
{
JInternalFrame jif = new JInternalFrame( "JIF2", false, false,
false, false );
jif.setBounds(110, 0, 150, 200);
Container jifcp = jif.getContentPane();
jifcp.add(new JTree(),BorderLayout.CENTER);
jif.setVisible(true);
desktopPane.add(jif);
return jif;
}//createInternalFrame
static void sleepThread(int mili)
{
Thread ct = Thread.currentThread();
try
{ ct.sleep(mili); }
catch(IllegalArgumentException e){}
catch(InterruptedException e){}
}// end sleepThread
}//class Test
ak - 28 Jan 2004 12:52 GMT
> I ant to use a border less window, therefore I'M not using JFrame for
> that. With Jframe it works perfectly.
just continue to use JFrame, but call setUndecorated(true);
____________
http://reader.imagero.com the best java image reader.
Karsten Lentzsch - 28 Jan 2004 15:47 GMT
> I'm having some problems with a start up/splash window (see example
> below).
I recommend to avoid Swing classes for a splash.
Using Swing requires to load and initialize many
classes and will typically take significant more time
to open the splash.
Use an AWT splash instead. To make sure you're not
using heavy operations, you may consider observing
the classes loaded at application startup time by
switching on the JRE's verbose class loading mode.
Hope this helps,
Karsten Lentzsch
JGoodies :: Java User Interface Design
anders - 30 Jan 2004 11:25 GMT
I do understand the atvantage of using AWT instead of Swing for
a startup window. But its rather useless until I've found a
solution for my 2 questions, until then I'll use the
suggested .setUndecorated(true);
Thomas Weidenfeller - 30 Jan 2004 11:51 GMT
> I do understand the atvantage of using AWT instead of Swing for
> a startup window. But its rather useless until I've found a
> solution for my 2 questions, until then I'll use the
> suggested .setUndecorated(true);
I suggest you better not rate the answers you get. Otherwise people
might start to rate the source code you posted. And that will not be
favorable for you.
/Thomas
ak - 30 Jan 2004 12:15 GMT
> I do understand the atvantage of using AWT instead of Swing for
> a startup window. But its rather useless until I've found a
> solution for my 2 questions, until then I'll use the
> suggested .setUndecorated(true);
setUndecorated(true) works also for Frame.
____________
http://reader.imagero.com the best java image reader.
DreamCoder - 30 Jan 2004 13:51 GMT
you are right!
Use AWT , try "awt splash screen" in google and you get tons of examples.
Roy Ratcliffe - 30 Jan 2004 14:44 GMT
> you are right!
> Use AWT , try "awt splash screen" in google and you get tons of examples.
Also, there's a thread further back in this newsgroup (around early
January this year) with some interesting views on /use/ and /abuse/ of
splash screens. Should splash screens display a progress bar? An good
question!
It turns out that splash screen implementation has some fascinating
technical challenges as well as human factors, especially when you
consider multiprocessor platforms. The thread includes a link to one
example of an AWT-based splash screen implementation, though in fact the
link doesn't work well on some browsers. Have a look at
http://www.aqss05.dsl.pipex.com if you have problems with the
freewebpage.org site.
Regards,
Roy

Signature
Roy Ratcliffe
Software Group Leader
Research & Development
Drew Scientific
royr@drew-scientific.com