• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing JFilechooser Color

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic