Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to handle JFrame minimize/restore?  RSS feed

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After minimizing and restoring JFrame I should refresh some informations on status bar.
Is there a way of achieving that?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WindowListener.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not working...
This is the idea behind my test code:

But message is not shown when I restore frame.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you add the WindowListener to the frame? In the constructor simply write "addWindowListener(this);".
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, now it works, but I'm confused.
My frame also implements KeyListener and MouseListener. I didn't add those listeners to my frame explicitly with:

but just implemented abstract methods. And it is working. How come?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I minimize application, change the state of CAPS LOCK and when I restore it, status bar indicator is not automatically refreshed.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:To get better help sooner, post a SSCCE.

Sorry, but I don't know what's wrong with the above code. I just put the segments of interest for the issue.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:I minimize application, change the state of CAPS LOCK and when I restore it, status bar indicator is not automatically refreshed.

Have you done any basic debugging? Do you know whether the windowDeiconified method is being called? What about the refreshStatusBarCapsIndicator method? And which of the two branches in the if-else statement is called?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did debugging, and did it again now.
windowDeiconified method is called when applicaion is restored.
Here is one scenario I used in debugging:

CAPS LOCK is off on application start.
I minimize application.
Change state of CAPS LOCK to on.
Restore application.
windowDeiconified is called
refreshStatusBarCapsIndicator() is called -> BUT getLockingKeyState returns false and it enters else branch.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your TextEditorView extends JFrame so it's suitable for window-listeners. But in initialize() you're creating a new instance within the instance.
So you're creating a unnecessary instance and assigning the window-listener to the wrong instance.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now in initialize() I just initialize other components (menu bar, toolbar, status bar, ...). But the problem remains.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:
Darryl Burke wrote:To get better help sooner, post a SSCCE.

Sorry, but I don't know what's wrong with the above code. I just put the segments of interest for the issue.

Of course, if you don't want to get better help sooner, that's your choice.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here is similar code, with the analog idea:


Is this code ok?

NOTE: I already posted this on DaniWeb, but nobody didn't offer the solution.

The scenario is the same:
CAPS LOCK is off on application start.
I minimize application.
On restore "Caps lock off" message is shown.
Minimize application again
Change the state of CAPS to on
On restore, "Caps lock off" is shown - Wrong!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:Is this code ok?

Is it really so difficult to go through the SSCCE link?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Kemal Sokolovic wrote:Is this code ok?

Is it really so difficult to go through the SSCCE link?

Short, since nothing can't be put out; working example that demonstrates the problem. The problem is strictly pointed out in the text following the code and previous posts above.
Is it really so difficult to tell what's wrong with this code???
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't compile. It needs at least several methods from WindowListener (with empty bodies).
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was exactly what I put in my post last night, but you said it was still wrong, so I removed methods with empty bodies.
I edited the post now, returning to what it contained previously. It compiles now. Hope it's ok.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the same behaviour. Caps changes are only seen when they are done if the window is active. Maybe you've found a bug; check Oracle's bug database.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bug is already reported in bug database
Thanks for help, and sorry for problems with posting codes!

Cheers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!