This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JWindow keeps refreshing or Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JWindow keeps refreshing or "flashing"" Watch "JWindow keeps refreshing or "flashing"" New topic
Author

JWindow keeps refreshing or "flashing"

Mark Siegrist
Greenhorn

Joined: Dec 16, 2006
Posts: 1
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

Joined: Jun 09, 2003
Posts: 4632
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
 
subject: JWindow keeps refreshing or "flashing"