1 2 Previous Next 23 Replies Latest reply: Sep 26, 2013 4:46 PM by NiXPhoE RSS

    Colors of JFilechooser

    NiXPhoE
      hello,
      I have following JFilechooser and like to make it completely black green without the icons. how is this possible?
      thank you
      public class Test {
      
           @SuppressWarnings("unused")
           private static WriteCfg writecfg;
           
           public static void main(String[] args) {
                writecfg = new WriteCfg();
      
           }
      
      }
      import java.io.*;
      
      public class ReadCfg
      {
           private String readpath;          //Path to System Shock 2.
           private String IniLanguage = "DE";    //Language of ShockCfg
           
           public String getreadpath()
           {
                return readpath;
           }
      
           public void setreadpath(String readpath)
           {
                this.readpath = readpath;
           }
           
           public String getIniLanguage()
           {
                return IniLanguage;
           }
      
           public ReadCfg()
           {
                try
                {
                     //open shockcfg.cfg
                     BufferedReader buffer = new BufferedReader( new FileReader("ShockCfg.ini"));
                     readpath = buffer.readLine();
                     IniLanguage = buffer.readLine();
                     buffer.close();
                }
                catch (IOException e) 
                {
                     //if shockcfg.cfg don't exists, open filechooser.
                     //new WriteCfg();          
                }          
           }
      }
      import java.awt.*;
      import java.io.BufferedReader;
      import java.io.BufferedWriter;
      import java.io.File;
      import java.io.FileReader;
      import java.io.FileWriter;
      import java.io.IOException;
      import java.util.Locale;
      
      import javax.swing.*;
      import javax.swing.border.Border;
       
      public class WriteCfg
      {
           private final JFileChooser dir;
           private int returnval;
           @SuppressWarnings("unused")
           private File shock2exe;
           private BufferedWriter bufferwrite;
           private ReadCfg readcfg;
           
      public WriteCfg()
           {
                readcfg = new ReadCfg();
                UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
                UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
                javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
                JDialog.setDefaultLookAndFeelDecorated(true);
                JOptionPane optPane = new JOptionPane("Please select System Shock 2 directory");
                optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
                JDialog dia = optPane.createDialog(null, "Please select System Shock 2 directory");
                dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
                changeColor(dia.getComponents());
                dia.setModal(true);
                dia.setVisible(true);
                //filechooser opening
                dir = new JFileChooser("Select Shock 2 Directory")
                {
                     /**
                      * 
                      */
                     private static final long serialVersionUID = 1L;
       
                     public JDialog createDialog(Component parent)
                     {
                          JDialog d = super.createDialog(parent);
                          d.getContentPane().setBackground(Color.black);
                          d.getContentPane().setForeground(Color.green);
                          Border border = BorderFactory.createLineBorder(Color.green);
                       UIManager.put("Button.border", border);
                       return d;
                     }
                };
                changeColor(dir.getComponents());
                dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                returnval = dir.showDialog(null, "Choose");
                if (returnval == JFileChooser.APPROVE_OPTION)
                {     
                     shock2exe = dir.getSelectedFile();
                     try 
                     {
                          //make shockcfg.cfg
                          bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
                          @SuppressWarnings("resource")
                          BufferedReader buffer = new BufferedReader( new FileReader("ShockCfg.ini"));
                          readcfg.setreadpath(buffer.readLine());
                          //thx to Al_B
                          bufferwrite.write("\r\n");
                          
                          Locale w = Locale.getDefault();
                          if(w.getLanguage().equalsIgnoreCase("GERMAN"))
                          {
                               bufferwrite.write("GERMAN");
                          }
                          else
                          {
                               bufferwrite.write("ENGLISH");
                          }
                          
                          bufferwrite.write("\r\n");
                          
                          bufferwrite.close();
                     } 
                     catch (IOException ex)
                     {
                          System.out.println("Error creating the file ShockCfg.cfg");
                          System.out.println(ex);
                          System.exit(0);
                     }
                }
                else
                {
                     System.exit(0);
                }
           }
           
           public void changeColor(Component[] comp)
           {
                for(int x=0; x<comp.length; x++)
                {
                     try
                     {
                          comp[x].setBackground(Color.black);
                          comp[x].setForeground(Color.green);
                     }
                     catch(Exception e) {}
                if(comp[x] instanceof Container)
                     changeColor(((Container)comp[x]).getComponents());
                }
           }
           
      }
      Edited by: NiXPhoE on 07.11.2012 09:16
        • 1. Re: Colors of JFilechooser
          NiXPhoE
          Program should work now. Anyknows how to make the Titlebar green black, green borders and green triangles?
          Thanks!
          • 2. Re: Colors of JFilechooser
            972409
            This might me helpful:

            [url http://stackoverflow.com/questions/10664715/set-own-file-icons-for-selected-files-on-jfilechooser]StackOverflow.com question thread
            • 3. Re: Colors of JFilechooser
              NiXPhoE
              Thank you, this changes the Images of the files, but I don't like to change this detail, I want only help for the rest. The Ok-Button at the beginning, the Borders and the Titlebar if the Dialog is not the active Window.
              • 4. Re: Colors of JFilechooser
                972409
                969180 wrote:
                The Ok-Button at the beginning, the Borders and the Titlebar if the Dialog is not the active Window.
                Can you please be more specific? Which Ok-Button? Of what? Beginning of what?

                Do you mean the logo? No idea what you want to do. Once you want no images and once you want a triangle.
                Send a picture.
                • 5. Re: Colors of JFilechooser
                  NiXPhoE
                  I have edited the first Message, so that it runs now.

                  There comes first a Dialog, which says "Please select System Shock 2 directory", and I mean it's Ok-Buttons Border.

                  Edited by: NiXPhoE on 07.11.2012 09:19
                  • 6. Re: Colors of JFilechooser
                    NiXPhoE
                    Who can help with these problems?

                    The border of the ok-button.
                    The borders of the Filechooser.
                    The two triangles of the Filechooser.
                    • 7. Re: Colors of JFilechooser
                      NiXPhoE
                      I have now the green border of the Ok-Button partly. It is only for another Dialog and the border resize dosn't work.
                      In the Filechooser there are now two more green borders, but two are anyway gray and the triangles are invisible.
                      This is the Code for this, thank you!
                      import java.io.*;
                      import java.awt.*;
                      
                      import javax.swing.*;
                      import javax.swing.border.Border;
                      
                      import java.util.Locale;
                      
                      public class WriteCfg
                      {
                           private final JFileChooser dir;
                           private int returnval;
                           private File shock2exe;
                           private BufferedWriter bufferwrite;
                           public SetRes setres;
                           public ReadCfg readcfg;
                           
                           public WriteCfg(SetRes setres, ReadCfg readcfg)
                           {
                                this.setres = setres;
                                this.readcfg = readcfg;
                                UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
                                UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
                                javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
                                JDialog.setDefaultLookAndFeelDecorated(true);
                                
                                try {
                                  UIManager.setLookAndFeel( new MyLookAndFeel() );
                              } catch (UnsupportedLookAndFeelException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                              }
                                
                                //Bottonborder
                                Border border = BorderFactory.createLineBorder(Color.green);
                              UIManager.put("Button.border", border);
                              
                              JOptionPane theOptionPane = new JOptionPane("ButtonYNAbortDia",
                                      JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                              JOptionPane optPane = new JOptionPane(setres.getTxt().getString("WriteCfgDia1"));
                                optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
                                JDialog dia = optPane.createDialog(null, setres.getTxt().getString("WriteCfgDia1"));
                                
                                //Border 
                                JPanel buttonPanel = (JPanel)theOptionPane.getComponent(1);
                              // get the handle to the ok button
                              JButton buttonOk = (JButton)buttonPanel.getComponent(0);
                              // set the text
                              buttonOk.setText(" OK ");
                              buttonOk.setPreferredSize(new Dimension(40,26));  //Set Button size here
                              buttonOk.validate();
                              
                              dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
                                changeColor(dia.getComponents());
                                dia.setModal(true);
                                dia.setVisible(true);
                                //filechooser opening
                                dir = new JFileChooser("Select Shock 2 Directory")
                                {
                                     /**
                                      * 
                                      */
                                     private static final long serialVersionUID = 1L;
                      
                                     public JDialog createDialog(Component parent)
                                     {
                                          JDialog d = super.createDialog(parent);
                                          d.getContentPane().setBackground(Color.black);
                                          d.getContentPane().setForeground(Color.green);
                                          return d;
                                     }
                                };
                                changeColor(dir.getComponents());
                                dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                                returnval = dir.showDialog(null, setres.getTxt().getString("WriteCfgDia2"));
                                if (returnval == JFileChooser.APPROVE_OPTION)
                                {     
                                     shock2exe = dir.getSelectedFile();
                                     try 
                                     {
                                          //make shockcfg.cfg
                                          bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
                                          readcfg.setreadpath(shock2exe.getPath());
                                          bufferwrite.write(readcfg.getreadpath());
                                          //thx to Al_B
                                          bufferwrite.write("\r\n");
                                          
                                          Locale w = Locale.getDefault();
                                          if(w.getLanguage().equalsIgnoreCase("GERMAN"))
                                          {
                                               bufferwrite.write("GERMAN");
                                          }
                                          else
                                          {
                                               bufferwrite.write("ENGLISH");
                                          }
                                          
                                          bufferwrite.write("\r\n");
                                          
                                          bufferwrite.close();
                                     } 
                                     catch (IOException ex)
                                     {
                                          System.out.println(setres.getTxt().getString("WriteCfgErr"));
                                          System.out.println(ex);
                                          System.exit(0);
                                     }
                                }
                                else
                                {
                                     System.exit(0);
                                }
                           }
                           
                           public void changeColor(Component[] comp)
                           {
                                for(int x=0; x<comp.length; x++)
                                {
                                     try
                                     {
                                          comp[x].setBackground(Color.black);
                                          comp[x].setForeground(Color.green);
                                     }
                                     catch(Exception e) {}
                                if(comp[x] instanceof Container)
                                     changeColor(((Container)comp[x]).getComponents());
                                }
                           }
                           
                      }
                      • 8. Re: Colors of JFilechooser
                        NiXPhoE
                        Can you please help with the four things, that are not green?
                        Thank you!
                        • 9. Re: Colors of JFilechooser
                          NiXPhoE
                          Hello,

                          I have now added Code for the Triangles, but Eclipse shows an Error. Does anyone know how to fix this bug?
                          My previouse question of the borders of the filetable and the other border still remain?

                          Thank you!
                          import java.io.*;
                          import java.awt.*;
                          
                          import javax.swing.*;
                          import javax.swing.border.Border;
                          import javax.swing.plaf.basic.BasicArrowButton;
                          import javax.swing.plaf.basic.BasicComboBoxUI;
                          import javax.swing.plaf.basic.BasicComboPopup;
                          import javax.swing.plaf.basic.ComboPopup;
                          
                          import java.util.Locale;
                          
                          public class WriteCfg
                          {
                               private final JFileChooser dir;
                               private int returnval;
                               private File shock2exe;
                               private BufferedWriter bufferwrite;
                               public SetRes setres;
                               public ReadCfg readcfg;
                               
                               public WriteCfg(SetRes setres, ReadCfg readcfg)
                               {
                                    this.setres = setres;
                                    this.readcfg = readcfg;
                                    UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
                                    UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
                                    javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
                                    JDialog.setDefaultLookAndFeelDecorated(true);
                                    
                                    try {
                                      UIManager.setLookAndFeel( new MyLookAndFeel() );
                                  } catch (UnsupportedLookAndFeelException e) {
                                      // TODO Auto-generated catch block
                                      e.printStackTrace();
                                  }
                                    
                                    //Bottonborder
                                    Border border = BorderFactory.createLineBorder(Color.green);
                                  UIManager.put("Button.border", border);
                                  
                                  JOptionPane theOptionPane = new JOptionPane("ButtonYNAbortDia",
                                          JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                                  JOptionPane optPane = new JOptionPane(setres.getTxt().getString("WriteCfgDia1"));
                                    optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
                                    JDialog dia = optPane.createDialog(null, setres.getTxt().getString("WriteCfgDia1"));
                                    
                                    //Border 
                                    JPanel buttonPanel = (JPanel)theOptionPane.getComponent(1);
                                  // get the handle to the ok button
                                  JButton buttonOk = (JButton)buttonPanel.getComponent(0);
                                  // set the text
                                  buttonOk.setText(" OK ");
                                  buttonOk.setPreferredSize(new Dimension(40,26));  //Set Button size here
                                  buttonOk.validate();
                                  
                                  dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
                                    changeColor(dia.getComponents());
                                    dia.setModal(true);
                                    dia.setVisible(true);
                                    //filechooser opening
                                    dir = new JFileChooser("Select Shock 2 Directory")
                                    {
                                         /**
                                          * 
                                          */
                                         private static final long serialVersionUID = 1L;
                          
                                         public JDialog createDialog(Component parent)
                                         {
                                              JDialog d = super.createDialog(parent);
                                              d.getContentPane().setBackground(Color.black);
                                              d.getContentPane().setForeground(Color.green);
                                              return d;
                                         }
                                    };
                                    changeColor(dir.getComponents());
                                    dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                                    returnval = dir.showDialog(null, setres.getTxt().getString("WriteCfgDia2"));
                                    if (returnval == JFileChooser.APPROVE_OPTION)
                                    {     
                                         shock2exe = dir.getSelectedFile();
                                         try 
                                         {
                                              //make shockcfg.cfg
                                              bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
                                              readcfg.setreadpath(shock2exe.getPath());
                                              bufferwrite.write(readcfg.getreadpath());
                                              //thx to Al_B
                                              bufferwrite.write("\r\n");
                                              
                                              Locale w = Locale.getDefault();
                                              if(w.getLanguage().equalsIgnoreCase("GERMAN"))
                                              {
                                                   bufferwrite.write("GERMAN");
                                              }
                                              else
                                              {
                                                   bufferwrite.write("ENGLISH");
                                              }
                                              
                                              bufferwrite.write("\r\n");
                                              
                                              bufferwrite.close();
                                         } 
                                         catch (IOException ex)
                                         {
                                              System.out.println(setres.getTxt().getString("WriteCfgErr"));
                                              System.out.println(ex);
                                              System.exit(0);
                                         }
                                    }
                                    else
                                    {
                                         System.exit(0);
                                    }
                               }
                               
                               public void changeColor(Component[] comp)
                               {
                                    for(int x=0; x<comp.length; x++)
                                    {
                                         try
                                         {
                                              comp[x].setBackground(Color.black);
                                              comp[x].setForeground(Color.green);
                                         }
                                         catch(Exception e) {}
                                    if(comp[x] instanceof Container)
                                         changeColor(((Container)comp[x]).getComponents());
                                    }
                               }
                          
                               class MyUIComboBox extends BasicComboBoxUI
                               {
                                 protected ComboPopup createPopup()
                                 {
                                   return new BasicComboPopup(comboBox){
                                     private static final long serialVersionUID = 1L;
                                         protected JScrollPane createScroller()
                                     {
                                       JScrollPane sp = super.createScroller();
                                       sp.setViewportBorder(new javax.swing.border.LineBorder(Color.GREEN));
                                       return sp;
                                     }
                                   };
                                 }
                                 protected ComboBoxEditor createEditor()
                                 {
                                   ComboBoxEditor cbe = super.createEditor();
                                   cbe.getEditorComponent().setBackground(Color.BLACK);
                                   cbe.getEditorComponent().setForeground(Color.GREEN);
                                   return cbe;
                                 }
                                 protected JButton createArrowButton()
                                 {
                                   return new MyLangBuBasicArrowButtonCB(BasicArrowButton.SOUTH,
                                   UIManager.getColor("ComboBox.buttonBackground"),
                                   UIManager.getColor("ComboBox.buttonShadow"),
                                   UIManager.getColor("ComboBox.buttonDarkShadow"),
                                   UIManager.getColor("ComboBox.buttonHighlight"));
                                 }
                               }
                               class MyLangBuBasicArrowButtonCB extends BasicArrowButton
                               {
                                 private static final long serialVersionUID = 1L;
                                    public MyLangBuBasicArrowButtonCB(int direction,Color background,Color shadow,Color darkShadow,Color highlight)
                                 {
                                     super(direction,background,shadow,darkShadow,highlight);
                                     setBackground(Color.BLACK);
                                     setBorder(new javax.swing.border.LineBorder(Color.GREEN));
                                 }
                                 public void paintTriangle(Graphics g,int x,int y,int size,int direction,boolean isEnabled)
                                 {
                                     Color oldColor = g.getColor();
                                     int mid, i, j;
                                     j = 0;
                                     size = Math.max(size, 2);
                                     mid = (size / 2) - 1;
                                     g.translate(x, y);
                                     g.setColor(Color.GREEN);
                                     j = 0;
                                     for(i = size-1; i >= 0; i--)
                                     {
                                         g.drawLine(mid-i, j, mid+i, j);
                                         j++;
                                     }
                                     g.translate(-x, -y);
                                     g.setColor(oldColor);
                                 }
                               }
                          }
                          • 10. Re: Colors of JFilechooser
                            NiXPhoE
                            I have now a SSCCE that shows like described, but no buttons.
                            Can you help please?
                            public class Test {
                            
                                 /**
                                  * @param args
                                  */
                                 public static void main(String[] args) {
                                      // TODO Auto-generated method stub
                                      new ReadCfg();
                                 }
                            
                            }
                            import java.io.*;
                            import java.awt.*;
                            
                            import javax.swing.*;
                            import javax.swing.border.Border;
                            import javax.swing.plaf.basic.BasicArrowButton;
                            import javax.swing.plaf.basic.BasicComboBoxUI;
                            import javax.swing.plaf.basic.BasicComboPopup;
                            import javax.swing.plaf.basic.ComboPopup;
                            
                            import java.util.Locale;
                            
                            public class WriteCfg
                            {
                                 private final JFileChooser dir;
                                 private int returnval;
                                 private File shock2exe;
                                 private BufferedWriter bufferwrite;
                                 private ReadCfg readcfg;
                                 
                                 public WriteCfg(ReadCfg readcfg)
                                 {
                                      readcfg = this.readcfg;
                                      UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
                                      UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
                                      javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
                                      JDialog.setDefaultLookAndFeelDecorated(true);
                                      
                                      try {
                                        UIManager.setLookAndFeel( new MyLookAndFeel() );
                                    } catch (UnsupportedLookAndFeelException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                      
                                      //Bottonborder
                                      Border border = BorderFactory.createLineBorder(Color.green);
                                    UIManager.put("Button.border", border);
                                    
                                    JOptionPane theOptionPane = new JOptionPane("ButtonYNAbortDia",
                                            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                                    JOptionPane optPane = new JOptionPane("Please select System Shock 2 Directory");
                                      optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
                                      JDialog dia = optPane.createDialog("Please select System Shock 2 directory");
                                      
                                      //Border 
                                      JPanel buttonPanel = (JPanel)theOptionPane.getComponent(1);
                                    // get the handle to the ok button
                                    JButton buttonOk = (JButton)buttonPanel.getComponent(0);
                                    // set the text
                                    buttonOk.setText(" OK ");
                                    buttonOk.setPreferredSize(new Dimension(40,26));  //Set Button size here
                                    buttonOk.validate();
                                    
                                    dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
                                      changeColor(dia.getComponents());
                                      dia.setModal(true);
                                      dia.setVisible(true);
                                      //filechooser opening
                                      dir = new JFileChooser("Select Shock 2 Directory")
                                      {
                                           /**
                                            * 
                                            */
                                           private static final long serialVersionUID = 1L;
                            
                                           public JDialog createDialog(Component parent)
                                           {
                                                JDialog d = super.createDialog(parent);
                                                Border border = BorderFactory.createLineBorder(Color.green);
                                              UIManager.put("Button.border", border);
                                              d.getContentPane().setBackground(Color.black);
                                                d.getContentPane().setForeground(Color.green);
                                                return d;
                                           }
                                      };
                                      changeColor(dir.getComponents());
                                      dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                                      returnval = dir.showDialog(null, "Choose");
                                      if (returnval == JFileChooser.APPROVE_OPTION)
                                      {     
                                           shock2exe = dir.getSelectedFile();
                                           try 
                                           {
                                                //make shockcfg.cfg
                                                bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
                                                readcfg.setreadpath(shock2exe.getPath());
                                                bufferwrite.write(readcfg.getreadpath());
                                                //thx to Al_B
                                                bufferwrite.write("\r\n");
                                                
                                                Locale w = Locale.getDefault();
                                                if(w.getLanguage().equalsIgnoreCase("GERMAN"))
                                                {
                                                     bufferwrite.write("GERMAN");
                                                }
                                                else
                                                {
                                                     bufferwrite.write("ENGLISH");
                                                }
                                                
                                                bufferwrite.write("\r\n");
                                                
                                                bufferwrite.close();
                                           } 
                                           catch (IOException ex)
                                           {
                                                System.out.println("Error creating ShockCfg.ini");
                                                System.out.println(ex);
                                                System.exit(0);
                                           }
                                      }
                                      else
                                      {
                                           System.exit(0);
                                      }
                                 }
                                 
                                 public void changeColor(Component[] comp)
                                 {
                                      for(int x=0; x<comp.length; x++)
                                      {
                                           try
                                           {
                                                comp[x].setBackground(Color.black);
                                                comp[x].setForeground(Color.green);
                                           }
                                           catch(Exception e) {}
                                      if(comp[x] instanceof Container)
                                           changeColor(((Container)comp[x]).getComponents());
                                      }
                                 }
                            
                                 class MyUIComboBox extends BasicComboBoxUI
                                 {
                                   protected ComboPopup createPopup()
                                   {
                                     return new BasicComboPopup(comboBox){
                                       private static final long serialVersionUID = 1L;
                                           protected JScrollPane createScroller()
                                       {
                                         JScrollPane sp = super.createScroller();
                                         sp.setViewportBorder(new javax.swing.border.LineBorder(Color.GREEN));
                                         return sp;
                                       }
                                     };
                                   }
                                   protected ComboBoxEditor createEditor()
                                   {
                                     ComboBoxEditor cbe = super.createEditor();
                                     cbe.getEditorComponent().setBackground(Color.BLACK);
                                     cbe.getEditorComponent().setForeground(Color.GREEN);
                                     return cbe;
                                   }
                                   protected JButton createArrowButton()
                                   {
                                     return new MyLangBuBasicArrowButtonCB(BasicArrowButton.SOUTH,
                                     UIManager.getColor("ComboBox.buttonBackground"),
                                     UIManager.getColor("ComboBox.buttonShadow"),
                                     UIManager.getColor("ComboBox.buttonDarkShadow"),
                                     UIManager.getColor("ComboBox.buttonHighlight"));
                                   }
                                 }
                                 class MyLangBuBasicArrowButtonCB extends BasicArrowButton
                                 {
                                   private static final long serialVersionUID = 1L;
                                      public MyLangBuBasicArrowButtonCB(int direction,Color background,Color shadow,Color darkShadow,Color highlight)
                                   {
                                       super(direction,background,shadow,darkShadow,highlight);
                                       setBackground(Color.BLACK);
                                       setBorder(new javax.swing.border.LineBorder(Color.GREEN));
                                   }
                                   public void paintTriangle(Graphics g,int x,int y,int size,int direction,boolean isEnabled)
                                   {
                                       Color oldColor = g.getColor();
                                       int mid, i, j;
                                       j = 0;
                                       size = Math.max(size, 2);
                                       mid = (size / 2) - 1;
                                       g.translate(x, y);
                                       g.setColor(Color.GREEN);
                                       j = 0;
                                       for(i = size-1; i >= 0; i--)
                                       {
                                           g.drawLine(mid-i, j, mid+i, j);
                                           j++;
                                       }
                                       g.translate(-x, -y);
                                       g.setColor(oldColor);
                                   }
                                 }
                            }
                            import javax.swing.UIDefaults;
                            import javax.swing.plaf.metal.MetalLookAndFeel;
                             
                            @SuppressWarnings("serial")
                            public class MyLookAndFeel  extends MetalLookAndFeel {  
                                    protected void initClassDefaults(UIDefaults table)   
                                    {  
                                        super.initClassDefaults(table);  
                                        table.put( "ButtonUI", "test.ButtonUI" );  
                                    }  
                                        
                            }
                            import java.awt.Color;
                            
                            class NoBumpsTheme extends javax.swing.plaf.metal.DefaultMetalTheme
                            {
                                 public javax.swing.plaf.ColorUIResource getPrimaryControlHighlight(){
                                      return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                 }
                                 
                                 public javax.swing.plaf.ColorUIResource getPrimaryControlDarkShadow(){
                                      return new javax.swing.plaf.ColorUIResource(Color.BLACK);
                                 }
                                 
                                 public javax.swing.plaf.ColorUIResource getPrimaryControlShadow(){
                                      return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                 }
                                 
                                 public javax.swing.plaf.ColorUIResource getPrimaryControl(){
                                      return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                 }
                            }
                            import java.io.*;
                            
                            public class ReadCfg
                            {
                                 private String readpath;          //Path to System Shock 2.
                                 private String IniLanguage = "DE";    //Language of ShockCfg
                                 @SuppressWarnings("unused")
                                 private ReadCfg readcfg;
                                 
                                 public String getreadpath()
                                 {
                                      return readpath;
                                 }
                            
                                 public void setreadpath(String readpath)
                                 {
                                      this.readpath = readpath;
                                 }
                                 
                                 public String getIniLanguage()
                                 {
                                      return IniLanguage;
                                 }
                            
                                 public ReadCfg()
                                 {
                                      try
                                      {
                                           //open shockcfg.cfg
                                           BufferedReader buffer = new BufferedReader( new FileReader("ShockCfg.ini"));
                                           readpath = buffer.readLine();
                                           IniLanguage = buffer.readLine();
                                           buffer.close();
                                      }
                                      catch (IOException e) 
                                      {
                                           //if shockcfg.cfg don't exists, open filechooser.
                                           new WriteCfg(this);          
                                      }          
                                 }
                            }
                            • 11. Re: Colors of JFilechooser
                              NiXPhoE
                              The SSCCE is not the same as my program. Can you please help with the WriteCfg and my program from www.shockcfg.org? I see no other way than asking this!

                              Sorry and thank you! :)
                              • 12. Re: Colors of JFilechooser
                                NiXPhoE
                                The problem with the SSCCE is in opposite to my program, that the buttons aren't shown. Anyone knows why this happens?
                                • 13. Re: Colors of JFilechooser
                                  NiXPhoE
                                  Michael Dunn you have a name in my tool, could you help again? :)
                                  • 14. Re: Colors of JFilechooser
                                    NiXPhoE
                                    Okay, I have now here a running SSCCE. Please help with my work. ;)
                                    If the button is pressed, the background isn't green and the letters aren't black.
                                    The file and directorylist don't has a green boder and also the Directoryname.
                                    The Titlebar has the wrong color if the window isn't the active one.
                                    Who can help with this last steps? ;))
                                    public class ShockCfg {
                                    
                                         /**
                                          * @param args
                                          */
                                         public static void main(String[] args) {
                                              // TODO Auto-generated method stub
                                              new ReadCfg();
                                         }
                                    
                                    }
                                    import java.io.*;
                                    import java.awt.*;
                                    
                                    import javax.swing.*;
                                    import javax.swing.border.Border;
                                    
                                    import java.util.Locale;
                                    
                                    public class WriteCfg
                                    {
                                         private final JFileChooser dir;
                                         private int returnval;
                                         private File shock2exe;
                                         private BufferedWriter bufferwrite;
                                         public ReadCfg readcfg;
                                         
                                         public WriteCfg(ReadCfg readcfg)
                                         {
                                              this.readcfg = readcfg;
                                              UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
                                              UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
                                              javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
                                              JDialog.setDefaultLookAndFeelDecorated(true);
                                              //Green border
                                              Border border = BorderFactory.createLineBorder(Color.green);
                                            UIManager.put("Button.border", border);
                                            
                                            JOptionPane optPane = new JOptionPane("Please select the System Shock 2 directory");
                                              optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
                                              JDialog dia = optPane.createDialog(null, ("Please select the System Shock 2 directory"));
                                              dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
                                              changeColor(dia.getComponents());
                                              dia.setModal(true);
                                              dia.setVisible(true);
                                              //filechooser opening
                                              dir = new JFileChooser("Select Shock 2 Directory")
                                              {
                                                   /**
                                                    * 
                                                    */
                                                   private static final long serialVersionUID = 1L;
                                    
                                                   public JDialog createDialog(Component parent)
                                                   {
                                                        JDialog d = super.createDialog(parent);
                                                        d.getContentPane().setBackground(Color.black);
                                                        d.getContentPane().setForeground(Color.green);
                                                        return d;
                                                   }
                                              };
                                              changeColor(dir.getComponents());
                                              dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                                              returnval = dir.showDialog(null, "Choose");
                                              if (returnval == JFileChooser.APPROVE_OPTION)
                                              {     
                                                   shock2exe = dir.getSelectedFile();
                                                   try 
                                                   {
                                                        //make shockcfg.cfg
                                                        bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
                                                        readcfg.setreadpath(shock2exe.getPath());
                                                        bufferwrite.write(readcfg.getreadpath());
                                                        //thx to Al_B
                                                        bufferwrite.write("\r\n");
                                                        
                                                        Locale w = Locale.getDefault();
                                                        if(w.getLanguage().equalsIgnoreCase("GERMAN"))
                                                        {
                                                             bufferwrite.write("GERMAN");
                                                        }
                                                        else
                                                        {
                                                             bufferwrite.write("ENGLISH");
                                                        }
                                                        
                                                        bufferwrite.write("\r\n");
                                                        
                                                        bufferwrite.close();
                                                   } 
                                                   catch (IOException ex)
                                                   {
                                                        System.out.println("Error creating file ShockCfg.ini");
                                                        System.out.println(ex);
                                                        System.exit(0);
                                                   }
                                              }
                                              else
                                              {
                                                   System.exit(0);
                                              }
                                         }
                                         
                                         public void changeColor(Component[] comp)
                                         {
                                              for(int x=0; x<comp.length; x++)
                                              {
                                                   try
                                                   {
                                                        comp[x].setBackground(Color.black);
                                                        comp[x].setForeground(Color.green);
                                                   }
                                                   catch(Exception e) {}
                                              if(comp[x] instanceof Container)
                                                   changeColor(((Container)comp[x]).getComponents());
                                              }
                                         }
                                         
                                    }
                                    import java.io.*;
                                    
                                    public class ReadCfg
                                    {
                                         private String readpath;          //Path to System Shock 2.
                                         private String IniLanguage = "DE";    //Language of ShockCfg
                                         
                                         public String getreadpath()
                                         {
                                              return readpath;
                                         }
                                    
                                         public void setreadpath(String readpath)
                                         {
                                              this.readpath = readpath;
                                         }
                                         
                                         public String getIniLanguage()
                                         {
                                              return IniLanguage;
                                         }
                                    
                                         public ReadCfg()
                                         {
                                              try
                                              {
                                                   //open shockcfg.cfg
                                                   BufferedReader buffer = new BufferedReader( new FileReader("ShockCfg.ini"));
                                                   readpath = buffer.readLine();
                                                   IniLanguage = buffer.readLine();
                                                   buffer.close();
                                              }
                                              catch (IOException e) 
                                              {
                                                   //if shockcfg.cfg don't exists, open filechooser.
                                                   new WriteCfg(this);          
                                              }          
                                         }
                                    }
                                    import java.awt.Color;
                                    
                                    class NoBumpsTheme extends javax.swing.plaf.metal.DefaultMetalTheme
                                    {
                                         public javax.swing.plaf.ColorUIResource getPrimaryControlHighlight(){
                                              return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                         }
                                         
                                         public javax.swing.plaf.ColorUIResource getPrimaryControlDarkShadow(){
                                              return new javax.swing.plaf.ColorUIResource(Color.BLACK);
                                         }
                                         
                                         public javax.swing.plaf.ColorUIResource getPrimaryControlShadow(){
                                              return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                         }
                                         
                                         public javax.swing.plaf.ColorUIResource getPrimaryControl(){
                                              return new javax.swing.plaf.ColorUIResource(Color.GREEN);
                                         }
                                    }
                                    1 2 Previous Next