here are all accesible keys for UIManager
(part of them aren't accessible by looping in UIManager
, for all supported Native OS's and standard LaFs), with notice that success is volatille, depends of Native OS and used LaF
you can to get parent from JFileChooser
, to cast to JDialog
add JFileChooser
to your own JDialog
(simple without any special settings, e.g. myDialog.add(myFileChooser);
+ myDialog.pack();
)
there is possible to play with components tree
all accesible keys for UIManager (part of them ....
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class Test extends JDialog {
private JFileChooser fc = null;
private JFrame bfcParent = null;
public Test(JFrame parent, boolean modal) {
super(parent, modal);
this.bfcParent = parent;
if (fc == null) {
fc = new JFileChooser();
fc.setAcceptAllFileFilterUsed(false);
fc.setLocale(Locale.ENGLISH);
UIManager.put("FileChooser.openDialogTitleText", "Open Dialog");
UIManager.put("FileChooser.saveDialogTitleText", "Save Dialog");
UIManager.put("FileChooser.lookInLabelText", "LookIn");
UIManager.put("FileChooser.saveInLabelText", "SaveIn");
UIManager.put("FileChooser.upFolderToolTipText", "UpFolder");
UIManager.put("FileChooser.homeFolderToolTipText", "HomeFolder");
UIManager.put("FileChooser.newFolderToolTipText", "New FOlder");
UIManager.put("FileChooser.listViewButtonToolTipText", "View");
UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
UIManager.put("FileChooser.fileNameHeaderText", "Name");
UIManager.put("FileChooser.fileSizeHeaderText", "Size");
UIManager.put("FileChooser.fileTypeHeaderText", "Type");
UIManager.put("FileChooser.fileDateHeaderText", "Date");
UIManager.put("FileChooser.fileAttrHeaderText", "Attr");
UIManager.put("FileChooser.fileNameLabelText", "Label");
UIManager.put("FileChooser.filesOfTypeLabelText", "filesOfType");
UIManager.put("FileChooser.openButtonText", "Open");
UIManager.put("FileChooser.openButtonToolTipText", "Open");
UIManager.put("FileChooser.saveButtonText", "Save");
UIManager.put("FileChooser.saveButtonToolTipText", "Save");
UIManager.put("FileChooser.directoryOpenButtonText", "Open Directory");
UIManager.put("FileChooser.directoryOpenButtonToolTipText", "Open Directory");
UIManager.put("FileChooser.cancelButtonText", "Cancel");
UIManager.put("FileChooser.cancelButtonToolTipText", "CanMMcel");
UIManager.put("FileChooser.newFolderErrorText", "newFolder");
UIManager.put("FileChooser.acceptAllFileFilterText", "Accept");
fc.updateUI();
SwingUtilities.updateComponentTreeUI(fc);
}
}
public int openFileChooser() {
//fc.setDialogTitle("Load File);
fc.resetChoosableFileFilters();
int returnVal = 0;
fc.setDialogType(JFileChooser.OPEN_DIALOG);
returnVal = fc.showDialog(this.bfcParent, "Load File");
if (returnVal == JFileChooser.APPROVE_OPTION) { //Process the results.
System.out.println("Opened");
} else {
System.out.println("Failed");
}
return returnVal;
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("FileChooser");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp = new JPanel(new BorderLayout());
JButton openButton = new JButton("Open File");
final Test test = new Test(frame, true);
openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
test.openFileChooser();
}
});
openButton.setEnabled(true);
jp.add(openButton, BorderLayout.AFTER_LAST_LINE);
frame.add(jp); //Add content to the window.
frame.pack();//Display the window.
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//Turn off metal's use of bold fonts
createAndShowGUI();
}
});
}
}