• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JWindow keeps refreshing or "flashing"

 
Mark Siegrist
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am putting together a JTable/TableModel based app but am having trouble with one of the finishing touches that I just assumed would be simple and work : (

When my little app starts the first thing that is visible is a JOptionPane that asks the user for their database username. Then I have another JOptionPane asking for the password, and then a couple of message panes just letting the user know some things. Those all work great but since they are not attached to a parent JFrame I thought it would be a good idea to have a solid-color JWindow to sit behind them, with the popups centered within the JWindow.

Everything appears fine at first until the user clicks on OK (or Cancel) in any of the popups. Once they click on one of those buttons, the JWindow seems to go away and then immediately gets repainted (I'm guessing that's what happens?) - in other words, it "flashes" on and off quickly as the new popup is drawn on the screen.

How do I stop this *very* annoying behavior?

Here is the relevant portion of my code:

public void buildGUI() {
//add a background to house the popups
splashWindow = new JWindow();
splashWindow.setBounds(200, 200, 900, 700);
splashWindow.setVisible(true);
splashWindow.toBack();
//ask user for username, and password via popups
dbUsername = JOptionPane .showInputDialog(splashWindow, "Please enter your database username.");
dbPassword = JOptionPane .showInputDialog(splashWindow, "Please enter your database password.");
JOptionPane.showMessageDialog(splashWindow, "Nickie: I'm using the following database/OS: Ubuntu Linux v6.10, MySql database.");
JOptionPane.showMessageDialog(splashWindow, "For this example I have 3 tables in my database: tblPayees, tblTransactions, and tblNotes.");
splashWindow.dispose();


P.S. I realize that asking the username/password in separate popups (and the password not being asked via a JPasswordField) is not the best way to do it - I do plan on eventually revising that approach.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for me it flickers only when a button of the first JOptionPane is clicked
java 1.5.0_05, win xp pro, p4 3.2

no flicker on java 1.4.0_01, win98se, celeron 500

don't know why, but if you add an additional setVisible(true), it no longer
flickers for the first JOptionPane

splashWindow.setVisible(true);
splashWindow.toBack();
splashWindow.setVisible(true);//<---added
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic