where MyFrame is something like this (logflag is a global variable, 0 by default):
So - at the start logflag equals 0, which means only 1st tab is active. When user enters his email and password and clicks the "Sign up" button, he sends his data to the server.
The server sends back the logflag. This bit works fine. The problem is when logflag is changed (to 1, 2 or 3) the application should disable the "Sign up" tab and enable "tmis", "sqt" or both.
The problem is, when I try frame.revalidate() or frame.repaint() nothing happens. The only effect I managed to get was when I called createAndShowGUI() again - it does disable "signup" tab and enable the rest, but the only "clickable" tab is still "signup" (and when clicked it resets whole application like when logflag is 0).
So, my question is: how can I refresh my JFrame so it redraw itself based on updated loglag parameter?
This won't answer your question, just an alternative.
Have you thought about setting it up as a CardLayout,
which is basically a JTabbedPane, but without tabs, where
you (might) use JMenuItems to navigate (or next/previous
buttons like in an installation wizard).
If JMenuItems, 'sign-up' is enabled, rest disabled, then on
succesful sign-up, the enabled/disabled menuItems are
reversed (you could even do this in the sign-up's overridden
One of the reason for UI not updating is if another process is occupying the thread. Normally, you should separate the UI processes from other long processes, by having one thread for the UI and another for long processes.
However, I think this may not be your problem.
One workaround I found, is by making certain component invisible, then make them visible again. This sort of refreshed/updated my UI. Which component to make invisible-then-visible? Try the component involved. If it doesnt work, try on its immediate container; and try further up until it works or it doesnt make sense anymore, at which, this technique wouldnt be useful anymore.
Jesus Angeles wrote:One workaround I found, is by making certain component invisible, then make them visible again.
Yuck! I can't think of a situation that would require that kind of 'workaround'
Have you tried revalidate() followed by repaint()?
There are no new questions, but there may be new answers.
Joined: Apr 18, 2009
Thanks for the replies!
@Darryl: I've already tried that, there was no effect.
@Michael: I'll try this if there's no other way, but the problem is somewhere else in the program I have to do another "refreshing" (well, not the entire jframe but only one jpanel) so I'm looking for the universal method to do this. I'm not sure if my way of thinking is correct but I was hoping there is a function like "refresh the GUI" or "hey, forget and destroy the previous GUI; build another one, but this time do it this way".
@Jesus: At the start I've tried something similar but because of the way rest of my program is built it's inconvenient and I had to change it. I'd prefer to change the components rather than show-or-hide them.
Thanks once again and if someone has other ideas I'd be happy to hear (or read in this case) them!
Joined: Feb 26, 2005
Yes, it is yuck but it worked.
What I did is something like this:
I thought it might cause a flicker, but so far, it is flawless when it runs; I am not sure though if this is the same on slower client pcs.
Joined: Jun 09, 2003
a different way of doing it
Joined: Apr 18, 2009
Thanks a lot! I modified it a bit so it would do exactly what I need and it works perfectly fine!