JFileChooser customizing

Hi guys,
I'm Having a save as JFileChooser dialog that i want to customize:
is it possible in the file chooser to hide the Save As (File Name) Label and the text box for File name entering ?
what is the simplest way to do that ?
thanking you much

the following method works correctly on linux & windows:
public void hide(Component[] comp)
      for(int x = 0; x < comp.length; x++)
        if(comp[x] instanceof JPanel) hide(((JPanel)comp[x]).getComponents());
        else if(comp[x] instanceof JTextField)
          ((JTextField)comp[x]).setVisible(false);
        else if(comp[x] instanceof JLabel)
             JLabel lbl=(JLabel)comp[x];
             if(lbl.getText().startsWith("Save As") || lbl.getText().startsWith("File Name") )
            lbl.setVisible(false);
    }However when i test on MAC the label Save As: is still displayed and the Save button is disabled. why this ?
can someone help me ?

Similar Messages

  • Disable approve button in jfileChooser (custom accessory)

    i'm using a custom accessory in a JFileChooser. i want to listen for selection events and en/dis-able the approve button depending on the selected item. how do i access the approve button. FileChooserUI has no method, BasicFileChooser has a protected getApproveButton() method. i don't see any properties that i can fire....i guess i could just "look" within the JFileChooser for the button but that seems awkward.
    any help much appreciated.

    Unfortunatly you can get the button only through the UI.
    Create a class extending the xxxFileChooserUI and create a method getApproveButton() :
    public void getApproveButton() {
    return(super.getApproveButton(null));
    Through the UIManager set the good UI for JFileChooser.
    I hope this helps,
    Denis

  • Strange behavior in JTable using JFileChooser as custom editor

    I have an application that I am working on that uses a JFileChooser (customized to select images) as a custom editor for a JTable. The filechooser correctly comes up when I click (single click) on a cell in the table. I can use the filechooser to select an image. When I click on the OPEN button on the filechooser, the cell then displays the editor class name.
    I have added prints to the editor methods and have determined that editing is stopped before the JTable adds the listener. I have looked at the code and have searched doc for examples but have not found what I am doing wrong. Can anyone help?
    I configured the table editor as follows:
    //Set up the editor for the Image cells.
    private void setUpPictureEditor(JTable table) {
    table.setDefaultEditor(String.class, new PictureChooser());
    Below is the code for the JTable editor that I am using:
    package com.board;
    import java.io.*;
    import java.util.Vector;
    import java.util.EventObject;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.event.CellEditorListener;
    import javax.swing.event.ChangeEvent;
    public class PictureChooser extends JLabel implements TableCellEditor
    boolean DEBUG = true;
    int line=0;
    static private String newline = "\n";
    protected boolean editing;
    protected Vector listeners;
    protected File originalFile;
    protected JFileChooser fc = new JFileChooser("c:\\java\\jpg");
    protected File newFile;
    public PictureChooser()
    super("PictureChooser");
    if (DEBUG)
         System.out.println(++line + "-PictureChooser constructor");
         listeners = new Vector();
         fc.addChoosableFileFilter(new ImageFilter());
         fc.setFileView(new ImageFileView());
         fc.setAccessory(new ImagePreview(fc));
    private void setValue(File file)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.setValue method");
         newFile = file;
    public Component getTableCellEditorComponent(JTable table,
                                  Object value,
                                  boolean isSelected,
                                  int row,
                                  int col)
    if (DEBUG)
         System.out.println(line + "-PictureChooser.getTableCellEditorComponent row:" + row + " col:" + col + " method");
         fc.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                   String cmd = e.getActionCommand();
                   System.out.println(++line + "-JFileChooser.actionListener cmd:" +
                                       cmd);
                   if (JFileChooser.APPROVE_SELECTION.equals(cmd))
                        stopCellEditing();
                   else
                        cancelCellEditing();
         //editing = true;
         //fc.setVisible(true);
         //fc.showOpenDialog(this);
         int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION)
         newFile = fc.getSelectedFile();
         table.setRowSelectionInterval(row,row);
         table.setColumnSelectionInterval(col,col);
         return this;
    // cell editor methods
    public void cancelCellEditing()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.cancelCellEditing method");
         fireEditingCanceled();
         editing = false;
         fc.setVisible(false);
    public Object getCellEditorValue()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.getCellEditorValue method");
         return new ImageIcon(newFile.toString());
    public boolean isCellEditable(EventObject eo)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.isCellEditable method");
         return true;
    public boolean shouldSelectCell(EventObject eo)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.shouldSelectCell method");
         return true;
    public boolean stopCellEditing()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.stopCellEditing method");
         fireEditingStopped();
         editing = false;
         fc.setVisible(false);
         return true;
    public void addCellEditorListener(CellEditorListener cel)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.addCellEditorListener method");
         listeners.addElement(cel);
    public void removeCellEditorListener(CellEditorListener cel)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.removeCellEditorListener method");
         listeners.removeElement(cel);
    public void fireEditingCanceled()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.fireEditingCanceled method");
         setValue(originalFile);
         ChangeEvent ce = new ChangeEvent(this);
         for (int i=listeners.size()-1; i>=0; i--)
         ((CellEditorListener)listeners.elementAt(i)).editingCanceled(ce);
    public void fireEditingStopped()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.fireEditingStopped method");
         ChangeEvent ce = new ChangeEvent(this);
         for (int i=listeners.size()-1; i>=0; i--)
    System.out.println(++line + "-PictureChooser listener " + i);
         ((CellEditorListener)listeners.elementAt(i)).editingStopped(ce);

    try this code. it work fine.
    regards,
    pratap
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.io.*;
    public class TableDialogEditDemo extends JFrame {
         public TableDialogEditDemo() {
              super("TableDialogEditDemo");
              MyTableModel myModel = new MyTableModel();
              JTable table = new JTable(myModel);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              //Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              //Set up renderer and editor for the Favorite Color column.
              setUpColorRenderer(table);
              setUpColorEditor(table);
              //Add the scroll pane to this window.
              getContentPane().add(scrollPane, BorderLayout.CENTER);
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
         private void setUpColorRenderer(JTable table) {
              table.setDefaultRenderer(File.class, new PictureRenderer(true));
         //Set up the editor for the Color cells.
         private void setUpColorEditor(JTable table) {
              table.setDefaultEditor(File.class, new PictureChooser());
         class PictureRenderer extends JLabel     implements TableCellRenderer {
              Border unselectedBorder = null;
              Border selectedBorder = null;
              boolean isBordered = true;
              public PictureRenderer(boolean isBordered) {
                   super();
                   this.isBordered = isBordered;
                   setOpaque(false);
                   setHorizontalAlignment(SwingConstants.CENTER);
              public Component getTableCellRendererComponent(
                                            JTable table, Object value,
                                            boolean isSelected, boolean hasFocus,
                                            int row, int column) {
                   File f = (File)value;
                   try {
                        setIcon(new ImageIcon(f.toURL()));
                   catch (Exception e) {
                   e.printStackTrace();
                   return this;
         class MyTableModel extends AbstractTableModel {
              final String[] columnNames = {"First Name",
                                                 "Favorite Color",
                                                 "Sport",
                                                 "# of Years",
                                                 "Vegetarian"};
              final Object[][] data = {
                   {"Mary", new Color(153, 0, 153), "Snowboarding", new Integer(5), new File("D:\\html\\f1.gif")},
                   {"Alison", new Color(51, 51, 153), "Rowing", new Integer(3), new File("D:\\html\\f2.gif")},
                   {"Philip", Color.pink, "Pool", new Integer(7), new File("D:\\html\\f3.gif")}
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              public boolean isCellEditable(int row, int col) {
                   if (col < 1) {
                        return false;
                   } else {
                        return true;
              public void setValueAt(Object value, int row, int col) {
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
         public static void main(String[] args) {
              TableDialogEditDemo frame = new TableDialogEditDemo();
              frame.pack();
              frame.setVisible(true);
    import java.awt.Component;
    import java.util.EventObject;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.io.*;
    public class PictureChooser extends JButton implements TableCellEditor, ActionListener {
         protected EventListenerList listenerList = new EventListenerList();
         protected ChangeEvent changeEvent = new ChangeEvent(this);
         private File file;
         public PictureChooser() {
              super("");
              setBackground(Color.white);
              setBorderPainted(false);
              setMargin(new Insets(0,0,0,0));
              addActionListener(this);
         public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected, int row, int column) {
         File f = (File)value;
         try {
              setIcon(new ImageIcon(f.toURL()));
         catch (Exception e) {
              e.printStackTrace();
         return this;
         public void actionPerformed(ActionEvent e)
         JFileChooser chooser = new JFileChooser("d:\\html");
         int returnVal = chooser.showOpenDialog(this);
              if(returnVal == JFileChooser.APPROVE_OPTION) {
                   file = chooser.getSelectedFile();
                   System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName());
                   fireEditingStopped();
              else
                   fireEditingCanceled();
         public void addCellEditorListener(CellEditorListener listener) {
         listenerList.add(CellEditorListener.class, listener);
         public void removeCellEditorListener(CellEditorListener listener) {
         listenerList.remove(CellEditorListener.class, listener);
         protected void fireEditingStopped() {
         System.out.println("fireEditingStopped called ");
         CellEditorListener listener;
         Object[] listeners = listenerList.getListenerList();
         for (int i = 0; i < listeners.length; i++) {
              if (listeners[i] == CellEditorListener.class) {
              listener = (CellEditorListener) listeners[i + 1];
              listener.editingStopped(changeEvent);
         protected void fireEditingCanceled() {
         CellEditorListener listener;
         Object[] listeners = listenerList.getListenerList();
         for (int i = 0; i < listeners.length; i++) {
              if (listeners[i] == CellEditorListener.class) {
              listener = (CellEditorListener) listeners[i + 1];
              listener.editingCanceled(changeEvent);
         public void cancelCellEditing() {
         System.out.println("cancelCellEditing called ");
         fireEditingCanceled();
         public boolean stopCellEditing() {
         System.out.println("stopCellEditing called ");
         fireEditingStopped();
         return true;
         public boolean isCellEditable(EventObject event) {
         return true;
         public boolean shouldSelectCell(EventObject event) {
         return true;
         public Object getCellEditorValue() {
              return file;

  • Get state of checkbox in customized JFileChooser

    I have built a custom JFileChooser that displays a JCheckBox as an accessory component.
    // build an accessory panel for the file chooser
    JPanel accesoryPanel = new JPanel(new GridLayout(2, 1));
    accesoryPanel.setBorder(BorderFactory.createTitledBorder("Export options"));
    JCheckBox checkbox = new JCheckBox ("Copy symbol files", isCopySymbolsDuringExportEnabled);
    accesoryPanel.add (checkbox);
    JFileChooser fc = new JFileChooser("c:\\temp");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setAccessory(accesoryPanel);
    int returnVal = fc.showDialog(null, "Choose export directory");
    exportDirectory = fc.getSelectedFile().getPath();
    How do I refer to the checkbox to see whether the user checked it or not?
    -Phil

    Nevermind. As soon as I hit send I realized I can simply do
    isCopySymbolsDuringExportEnabled= checkbox.isSelected();

  • Ordering of files once a custom FileView has been set in a JFileChooser.

    My end user has a requirement for custom icons in a JFileChooser. I have created a custom FileView but find that the ordering of files and directories is different to the order presented in the default FileView.
    For example in the default FileView, the directories are listed first and the files next.
    In my custom FileView, I see that the files and directories are listed in ascending alphabetical order, so that files and directories are all listed together.
    Attempting to alter the order using a custom FileSystemView with the method public File[] getFiles(File dir,boolean useFileHiding) where the returned file array is in the required order, is still defeated.
    I would be grateful for some assistance.

    I've tried it, but it will only accept an ID in the new format, i.e., an email address.  The old ID was a 7 character alpha only.

  • JFileChooser not opening when we applied custom Look and Feel & Theme

    Dear All,
    JFileChooser not opening when we applied custom Look and Feel & Theme.
    The following is the source code
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalLookAndFeel;
    import com.jgoodies.looks.plastic.*;
    public class CustomTheme {
    public static void main(String[] args)throws UnsupportedLookAndFeelException{
    UIManager.setLookAndFeel(new MyLookAndFeel());
    MyLookAndFeel.setCurrentTheme(new CustomLaF());
    JFrame frame = new JFrame("Metal Theme");
    JFileChooser jf = new JFileChooser();
    System.out.println("UI - > "+jf.getUI());
    //jf.updateUI();
    frame.getContentPane().add(jf);
    frame.pack();
    frame.setVisible(true);
    static class CustomLaF extends PlasticTheme {
    protected ColorUIResource getPrimary1() {
    return new ColorUIResource(232,132,11);
    public ColorUIResource getPrimary2() {
              return (new ColorUIResource(Color.white));
         public ColorUIResource getPrimary3() {
              return (new ColorUIResource(232,132,11));
    public ColorUIResource getPrimaryControl() {
    return new ColorUIResource(Color.GREEN);
    protected ColorUIResource getSecondary1() {
    return new ColorUIResource(Color.CYAN);
    protected ColorUIResource getSecondary2() {
              return (new ColorUIResource(Color.gray));
         protected ColorUIResource getSecondary3() {
              return (new ColorUIResource(235,235,235));
         protected ColorUIResource getBlack() {
              return BLACK;
         protected ColorUIResource getWhite() {
              return WHITE;
    static class MyLookAndFeel extends Plastic3DLookAndFeel {
              protected void initClassDefaults(UIDefaults table) {
                   super.initClassDefaults(table);
              protected void initComponentDefaults(UIDefaults table) {
                   super.initComponentDefaults(table);
                   Object[] defaults = {
                             "MenuItem.foreground",new ColorUIResource(Color.white),
                             "MenuItem.background",new ColorUIResource(Color.gray),
                             "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                             "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                             "Menu.selectionForeground", new ColorUIResource(Color.white),
                             "Menu.selectionBackground", new ColorUIResource(Color.gray),
                             "MenuBar.background", new ColorUIResource(235,235,235),
                             "Menu.background", new ColorUIResource(235,235,235),
                             "Desktop.background",new ColorUIResource(235,235,235),
                             "Button.select",new ColorUIResource(232,132,11),
                             "Button.focus",new ColorUIResource(232,132,11),
                             "TableHeader.background", new ColorUIResource(232,132,11),
                             "TableHeader.foreground", new ColorUIResource(Color.white),
                             "ScrollBar.background", new ColorUIResource(235,235,235),
                             "ToolTip.foreground", new ColorUIResource(232,132,11),
                             "ToolTip.background", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                             "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.titlePane.background", new ColorUIResource(232,132,11),
                             "Table.selectionBackground", new ColorUIResource(232,132,11)
                   table.putDefaults(defaults);
    When i run this program the following error is coming:
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(Unknown Source)
    at javax.swing.SwingUtilities.layoutCompoundLabelImpl(Unknown Source)
    at javax.swing.SwingUtilities.layoutCompoundLabel(Unknown Source)
    at javax.swing.plaf.basic.BasicLabelUI.layoutCL(Unknown Source)
    at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI$ListSelectionHandler.valueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source)
    at javax.swing.JList.setSelectedIndex(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup.setListSelection(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup.access$000(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$ItemHandler.itemStateChanged(Unknown Source)
    at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
    at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
    at javax.swing.JComboBox.contentsChanged(Unknown Source)
    at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.setSelectedItem(Unknow
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.addItem(Unknown Source
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.access$2300(Unknown So
    at javax.swing.plaf.metal.MetalFileChooserUI.doDirectoryChanged(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI.access$2600(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI$12.propertyChange(Unknown Source)
    at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
    at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
    at javax.swing.JComponent.firePropertyChange(Unknown Source)
    at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
    at javax.swing.JFileChooser.<init>(Unknown Source)
    at javax.swing.JFileChooser.<init>(Unknown Source)
    at CustomTheme.main(CustomTheme.java:20)
    I am extending the JGoodies Look And Feel & Theme.
    Thanks in advance
    Krishna Mohan.

    Dear cupofjoe,
    Thank you for your response.
    I am using the Latest JGoodies Look & Feel which is downloaded from http://www.jgoodies.com.
    i am writing our own custom Look & Feel By Overridding Jgoodies Look & Feel.
    In that case i am getting that error.
    The following is the source code:
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalLookAndFeel;
    import com.jgoodies.looks.plastic.*;
    public class CustomTheme {
    public static void main(String[] args)throws UnsupportedLookAndFeelException{
    UIManager.setLookAndFeel(new MyLookAndFeel());
    MyLookAndFeel.setCurrentTheme(new CustomLaF());
    JFrame frame = new JFrame("Metal Theme");
    JFileChooser jf = new JFileChooser();
    //System.out.println("UI - > "+jf.getUI());
    //jf.updateUI();
    //frame.getContentPane().add(jf);
    frame.pack();
    frame.setVisible(true);
    static class CustomLaF extends PlasticTheme {
    protected ColorUIResource getPrimary1() {
    return new ColorUIResource(232,132,11);
    public ColorUIResource getPrimary2() {
              return (new ColorUIResource(Color.white));
         public ColorUIResource getPrimary3() {
              return (new ColorUIResource(232,132,11));
    public ColorUIResource getPrimaryControl() {
    return new ColorUIResource(Color.GREEN);
    protected ColorUIResource getSecondary1() {
    return new ColorUIResource(Color.CYAN);
    protected ColorUIResource getSecondary2() {
              return (new ColorUIResource(Color.gray));
         protected ColorUIResource getSecondary3() {
              return (new ColorUIResource(235,235,235));
         protected ColorUIResource getBlack() {
              return BLACK;
         protected ColorUIResource getWhite() {
              return WHITE;
    static class MyLookAndFeel extends Plastic3DLookAndFeel {
              protected void initClassDefaults(UIDefaults table) {
                   super.initClassDefaults(table);
              protected void initComponentDefaults(UIDefaults table) {
                   super.initComponentDefaults(table);
                   Object[] defaults = {
                             "MenuItem.foreground",new ColorUIResource(Color.white),
                             "MenuItem.background",new ColorUIResource(Color.gray),
                             "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                             "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                             "Menu.selectionForeground", new ColorUIResource(Color.white),
                             "Menu.selectionBackground", new ColorUIResource(Color.gray),
                             "MenuBar.background", new ColorUIResource(235,235,235),
                             "Menu.background", new ColorUIResource(235,235,235),
                             "Desktop.background",new ColorUIResource(235,235,235),
                             "Button.select",new ColorUIResource(232,132,11),
                             "Button.focus",new ColorUIResource(232,132,11),
                             "TableHeader.background", new ColorUIResource(232,132,11),
                             "TableHeader.foreground", new ColorUIResource(Color.white),
                             "ScrollBar.background", new ColorUIResource(235,235,235),
                             "ToolTip.foreground", new ColorUIResource(232,132,11),
                             "ToolTip.background", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                             "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.titlePane.background", new ColorUIResource(232,132,11),
                             "Table.selectionBackground", new ColorUIResource(232,132,11)
                   table.putDefaults(defaults);
    pls suggest me the how to solve this problem.
    thanks in advance
    Krishna MOhan

  • Help with custom JFileChooser

    Hello everyone,
    I would like to customize JFileChooser to display a panel with some text above the folder browse section.
    Is this possible... if so, could anyone provide some sample code on how to get this started?

    I'm afraid you're on your own. Noone has [ever done something like that before|http://www.google.com/search?q=customizing jfilechooser].

  • Custom JFileChooser painting

    Hi all, still new at swing and customizing their look and have a few questions regarding customizing the painting of a JFileChooser. First I would like to change the gradients of the buttons. Is this possible? Usually I have gone about changing a components paintComponent method(as below). But I have no idea how to do this when trying to set the painting of a child component. Probably possible to loop also through the child components and find the buttons, but then what?
    Second I had used a recursive method to set child jpanel components of a JOptionPane to set them opaque and allow the JOptionPanes new custom paint to show through. I tried to apply that to the JFileChooser and am left with an area at the bottom and left that are the default colors.
    I have added statement to also change any JComponent to setOpaque(false), but this doesnt help. Any suggestions or help would be appreciated.
    heres the sample and thanks again.
    package filechoosertest;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Insets;
    import java.awt.RenderingHints;
    import javax.swing.JComponent;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class TestFileChooser extends JFileChooser{
        private Color startColor1 = new Color(255,255,255);
        private Color endColor1 = new Color(207,212,206);
         public static void main(String[] args) {
            // TODO code application logic here
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                 TestFileChooser tfc = new TestFileChooser();
                 tfc.showOpenDialog(null);
        public TestFileChooser(){
            super();
             mySetOpaque(this);
         protected void mySetOpaque(JComponent jcomp) {
            Component[] comps = jcomp.getComponents();
            for (Component c : comps) {
                System.err.println("Component class " + c.getClass().getName());
                if (c instanceof JPanel) {
                    System.err.println("Setting opaque");
                    ((JPanel) c).setOpaque(false);
                    mySetOpaque((JComponent) c);
         public void paintComponent(Graphics g) {
            Dimension dim = getSize();
            Graphics2D g2 = (Graphics2D) g;
            Insets inset = getInsets();
            int vWidth = dim.width - (inset.left + inset.right);
            int vHeight = dim.height - (inset.top + inset.bottom);
            paintGradient(g2, inset.left,
                    inset.top, vWidth, vHeight, dim.height);
             private void paintGradient(Graphics2D g2d, int x, int y,
                int w, int h, int height) {
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            GradientPaint GP = new GradientPaint(0, h * 3 / 4, startColor1, 0, h, endColor1, false);
            g2d.setPaint(GP);
            g2d.setPaint(GP);
            g2d.fillRect(1, 1, w, h);
    }

    Your problem, I think, is that you are not setting the opaque on JPanels nested within other JPanels. a small recursive routine should fix this:
      public MyOptionPane(Object message, int messageType, int optionType,
          Icon icon, Object[] options, Object initialValue) {
        super(message, messageType, optionType, icon, options, initialValue);
        mySetOpaque(this);
      private void mySetOpaque(JComponent jcomp)
        Component[] comps = jcomp.getComponents();
        for (Component c : comps) {
          if (c instanceof JPanel) {
            ((JPanel)c).setOpaque(false);
            mySetOpaque((JPanel)c);
      }

  • Custom JFileChooser

    Hallo,
    I created a custom filechooser dialog by putting a JFileChooser component on a panel of my dialog. I need to have a SAVE dialog. I did set the type to SAVE_DIALOG, did hide the control buttons...
    When I do not select any file but write the name of the file in the textfield (of the JFileChooser component) I cannot access the file by getSelectedFile(), because this is null.
    If i do not hide the control buttons and click to the approve button, I can access the file with getSelectedFile().
    What happens, when the approve button is pressed? And what do I need to do to get the filename?
    Thanks a lot.
    Steffen

    Some code would be appreciated, otherwise it's more difficult to recreate your scenario. Keep the code as minimal as can be though.
    Cheers.

  • Customizing JFIleChooser

    Hi,
    I have an issue with JFileChooser. My application uses a JFileChooser to select a folder location. I need to customize the JFileChooser so that the user shud be able to select folders and only view files not select it. He shud be allowed to select/open only folders, not the files within it.
    Thanks

    Read the API docs... there's an option for DIRECTORIES_ONLY

  • Customizing JFileChooser using Synth

    I'm creating custom Look&Feel using synth, and I'm having problems with the toggle buttons which commute between list view an table view. I'm unable to set the inset margins for thos buttons,
    I've tried to use:
         <property key="JToggleButton.margin" type="insets" value="4 4 4 4"/>
    and
         <property key="ToggleButton.margin" type="insets" value="4 4 4 4"/>
    with no success.
    Any ideas ?

    user1285890 wrote:
    Which thread ?The first thread you started: Splash screen in stand alone FXML application
    db

  • Customizing JFileChooser (File Size) Need Help

    Can you help me with this. I want to customize my JFileChooser. I'm in a Windows environment so the file view that I see is same with that of the option pane of windows. What I would like to do is make the size that is viewed from the screen from ##KB to specific bytes size. (ex. 34421245). Can someone help me on this. I was able to see some codes on the net but those codes are not straightforward. They override the BasicFileChooserUI. Can someone help me on this. I don't want to override the BasicFileChooserUI instead I want to use the JFileChooser and change the size from ###KB to bytes. Thank you. ^_^

    Hi Rachel,
    My best idea for that is to load the swf files externally, so
    that each page is a different swf. A technique like this would be
    very simple and quick to use, because it only loads what you need
    when you need it.
    For example, you'd set the intro page to load right away, and
    then when you select "At Work" the intro page unloads and is
    replaced by the at work page.
    Another thing you may want to consider is holding the images
    in an xml file, and then using some basic flash/xml intergration to
    load each image as it's called. That way each image isn't stored in
    the flash file causing it to increase in size, and instead is
    actually loaded externally which is must faster.
    There are some great tutorials, if you're intrested, on how
    to do both of these at:
    http://www.kirupa.com/
    Hope I helped some!

  • How can JFileChooser display custom ShellFolders ?

    The windows flavor of the JFileChooser UI has a nice left column with ShellFolder entries.
    How can one extend this list to add one's own places like "My workgroup's common place"
    or "My Shared folder" ?
    I've tried to implement a decorator for the FileSystemView, but is doesn't really help and
    has synchronization problems (getRoots() has to be fully operational on the JFileChooser creation),
    is there a way to force a FileSystemView rescan for new folders ?

    Yup, possible using system variables that can track time and conditional advanced actions.

  • Custom contents in JFilechooser

    Hi,
    How can I use the File chooser dialog to display not my hard disk contents but say a tree that i pass to it?

    Create your own subclass of javax.swing.filechooser.FileSystemView. This is rather
    tricky, but can be done.

  • Can not sort the files in JFileChooser if the files are from remote machine

    Hi All,
    Let me set the context of the question.
    I have extended the JFileChooser to support the listing/view of files.dirs etc of remote location through CORBA.To achieve that i have customized
    my FileSystemView to support it. In general ,the current JFileChooser sorts the file when we have details view .My question is related to this.The default
    JFileChooser has the support for sorting but when i customized the FileSystemView,the sorting functionality is no more exist.I tried with TableRowSorter as well but
    the sorting can be achieved in View only,the model still remains same as initial.
    Any pointer towards this will be highly appreciated.
    Thanks
    Praveen

    Can anyone help me out to solve this problem or any suggestion regarding this ?
    Regards
    Praveen

Maybe you are looking for

  • Starting deployment prerequisites: error in BI-Java installation sapinst

    Hi all, We are in process updating Bw 3.5 to BI 7.0 we hace sucessfully completed the Upgrade but while installing Bi java thru Sapinst in third step like java instance installtion  i was stck with the below error.            We have downloaded the C

  • Report to display on internet

    Dear friends, i got some critical requirement hope u can provide some solution Client got one MIS report on execution it is displaying in Excel format the requirement is on execution it should display in Excel sheet as well on internet. i just wanna

  • Need to transfer music

    I need help. I bought a laptop and I want to put my music from my desktop onto my laptop. averATEC   Windows XP  

  • Active status of "sub network" exists indicator activity

    Hi Friends Activity elements have been added to an Activity,  still "sub-network" check box is inactive on overview screen. All the relevant data have added or copied from patent activty. - when can we view that <b>"active</b>" check box - <b>subnetw

  • Import WebSite and Business Data Connectivty Services together

    Hi, On my development environment (SharePoint 2013 server), I have a web site that contains a documenbt list. This document list is linked to some Business Data Connectivity Objects. (I have some external data columns plugged on my BDC objects). Now,