This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing JFilechooser Color  RSS feed

 
nilesh sironja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dear friends,
I'm dealing with, change the content pane color of jFilechooser. Color has been changed but the problem is when I open the subdirectory leads errors;
Note : It also trigger error when I set default directory; like chooser.setCurrentDirectory(file);
Please help me.

The following error is the result:



Following is the code base

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags I have added them this time for you. As you can see the tags make the code much more easier to read and understand.

The following error is the result:

Please post your full stack trace
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you adding an action listener to your file chooser? That is not necessary. You can read about file choosers in the Java® Tutorials.
Doesn't the file chooser have a setBackground method? I thought all components had a setBackground method.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After going through whatever I could trace, I've found a workaround for what I believe to be a bug in the Swing code. Add one line:By the way, as a courtesy to those who copy and run your code, you should setDefaultCloseOperation(EXIT_ON_CLOSE) for any JFrame.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Related bug reports:

Some code of the JFileChooser#updateUI method should be moved into their setUI method
The reason is following: updateUI is not called when UI is set. Current implementation can produce some errors...


NPE thrown when overriding setUI method of JFileChooser
The method updateUI() is JFileChooser first calls setUI() then updates the
uiFileView value from the new UI instance. If the setUI() method is called
from anywhere else, then this update is not performed.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:After going through whatever I could trace, I've found a workaround for what I believe to be a bug in the Swing code.

Sorry, that was wrong. updateUI() resets the UI to the default from the UIManager, losing all customization.

This works:
 
nilesh sironja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darryl; given last (setFileView(...)) is work fine as well as UpdateUI() also, but as you suggest it might lose the cutomization, so I would go with setFileView(...).

Thanks a lot for you precious help.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. It can be very annoying to want to do something, and run up against a bug in the JDK!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!