2017-08-21 1 views
0

それがここに表示されるようJFileChooserの中にフォルダ名のフォントが、小さな表示された高解像度4K画面に私のJavaプログラムを実行している:Java - JFileChooserでフォルダ名のフォントを増やすにはどうすればよいですか?

enter image description here

私はフォルダを高めるための方法を見つけようとしています/ファイル名のフォントサイズは、JFileChooserでのみ指定します。私が持っている現在のアイデアは、カスタムJFileChooserを作成し、その要素をループし、フォルダ名のフォントを増やすことです。私はFilePaneのフォントを増やすと思ったが、うまくいかなかった。何も起こりません。私は、誰かがこれで私を助けることを願っ

public class JFileChooserCustom extends JFileChooser { 
    public JFileChooserCustom() { 
     setFileChooserFont(this.getComponents()); 
    } 

    public void setFileChooserFont(Component[] comp) { 
     for(int x = 0; x < comp.length; x++) { 
      // System.out.println(comp[x].toString()); // Trying to know the type of each element in the JFileChooser. 
      if(comp[x] instanceof Container) setFileChooserFont(((Container)comp[x]).getComponents()); 

      try{ 
       if(comp[x] instanceof FilePane) comp[x].setFont(comp[x].getFont().deriveFont(comp[x].getFont().getSize() * 2f)); 
      } 
      catch(Exception e){}//do nothing 
     } 
    } 
} 

:ここに私のコードです。

+0

「ファイルブラウザのGUI」(http://codereview.stackexchange.com/q/4446/7784)も参照してください。あなたが 'JFileChooser'をあきらめて置き換えることを決めた場合に備えてください。 –

+0

@Andrew Thompson ...ありがとうございますが、非常に進んでいるようです。私はそのような洗練された選択肢は必要ありません:) – Brad

答えて

1

FilePaneでは動作しません。代わりにJListとJTableを使用してください(これらのコンポーネントはFilePaneでファイルリストを表示するために使用されます)。

import java.awt.Component; 
import java.awt.Container; 

import javax.swing.JFileChooser; 
import javax.swing.JList; 
import javax.swing.JTable; 
import javax.swing.SwingUtilities; 

/** 
* <code>IncreaseFileChooserFont</code>. 
*/ 
public class IncreaseFileChooserFont { 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 

      @Override 
      public void run() { 
       JFileChooser chooser = new JFileChooser(); 
       setFileChooserFont(chooser.getComponents()); 
       chooser.showOpenDialog(null); 
       System.exit(0); 
      } 
     }); 
    } 

    public static void setFileChooserFont(Component[] comp) { 
     for (int x = 0; x < comp.length; x++) { 
      // System.out.println(comp[x].toString()); // Trying to know the type of each element in the JFileChooser. 
      if (comp[x] instanceof Container) 
       setFileChooserFont(((Container) comp[x]).getComponents()); 

      try { 
       if (comp[x] instanceof JList || comp[x] instanceof JTable) 
        comp[x].setFont(comp[x].getFont().deriveFont(comp[x].getFont().getSize() * 2f)); 
      } catch (Exception e) { 
      } // do nothing 
     } 
    } 
} 
0

これは、JFilechooserの各コンポーネントのフォントを個別に設定することで可能です。

// Inside method where you are preparing your JFilechooser: 
JFileChooser fc = new JFileChooser("."); 
setFileChooserFont(fc.getComponents()); 

public void setFileChooserFont(Component[] comp) 
{ 
    for(int x = 0; x < comp.length; x++) 
    { 
     if(comp[x] instanceof Container) setFileChooserFont(((Container)comp[x]).getComponents()); 
     try{comp[x].setFont(font);} 
     catch(Exception e){}//do nothing 
    } 
} 

は、これが役立つことを願っています。 :-)

関連する問題