• Post Reply Bookmark Topic Watch Topic
  • New Topic

Background Color for JFileChooser  RSS feed

 
Muzammil Khan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using repaint().
It's not advisable to use \ as path Separator. rether use java.io.File.pathSeparator.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!