• 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

Background Color for JFileChooser

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I would be very greteful if some one helps me with this problem.
I am trying to set the background color og the JFileChooser object that I have created. I have tried setBackground() method of the class, however no luck!
Here is my Code

public void openFile() {
// display file dialog, so user can choose file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setBackground(Color.decode("#EFEBDE")) ;
fileChooser.setForeground(Color.decode("#EFEBDE")) ;
fileChooser.setFileSelectionMode(
JFileChooser.DIRECTORIES_ONLY);
int result = fileChooser.showSaveDialog(this);
// if user clicked Cancel button on dialog, return
if (result == JFileChooser.CANCEL_OPTION)
return;
// get selected file
File fileName = fileChooser.getSelectedFile();
// display error if invalid
if (fileName == null ||
fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,
"Invalid File Name", "Invalid File Name",
JOptionPane.ERROR_MESSAGE);
else {
StringBuffer tempBuffer = new StringBuffer();
// open file
for (int i = 0; i < fileName.getAbsolutePath().toString().length(); i++) {
if (fileName.getAbsolutePath().toString().charAt(i) == '\\') {
tempBuffer.append(fileName.getAbsolutePath().toString().charAt(i));
tempBuffer.append("\\");
}
else {
tempBuffer.append(fileName.getAbsolutePath().toString().charAt(i));
}
}
tempBuffer.append('\\');
tempBuffer.append('\\');
archieveTextField.setText(tempBuffer.toString());
archieveTextField.setEditable(false);
}
} // end method openFile
It would be a great favour if this can be solved ASAP!
Kind Regards to all!
Muzz
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using repaint().
It's not advisable to use \ as path Separator. rether use java.io.File.pathSeparator.
 
reply
    Bookmark Topic Watch Topic
  • New Topic