2011-07-17 6 views
1

私はJFileChooserのを持っていると私はそれが右から左から指向にするために、そして私が使用したいと思う:RTLを設定するJFileChooserの内部でスクロールバーの向きを設定しますか?

applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 

が、問題が表示されます。 JFileChooserダイアログでRTLが正しく設定されているにもかかわらず、水平スクロールバーが左に設定されています。この画像を見て:

enter image description here

私はそれをどのように修正することができますか?ここで

がSSCCEです:

import javax.swing.JOptionPane; 
import javax.swing.UIManager; 
import javax.swing.JFileChooser; 
import javax.swing.filechooser.FileNameExtensionFilter; 
import javax.swing.filechooser.FileView; 
import java.io.File; 
import java.awt.ComponentOrientation; 
import java.awt.Dimension; 
public class MyFileChooser extends JFileChooser 
{ 
    private String extension; 
    private String title; 
    public MyFileChooser(String extension, String title) 
    { 
     super(); 
     this.extension = extension; 
     this.title = title; 
     addChoosableFileFilter(new FileNameExtensionFilter(String.format("(*.%1$s) فقط %1$s ملفات", extension), extension)); 
     applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
    } 

    @Override public String getDialogTitle() 
    { 
     return title; 
    } 
} 

メイン:

import java.awt.*; 
    import javax.swing.*; 
    import javax.swing.border.*; 
    import java.awt.event.*; 
    public class MainFrame extends JFrame implements ActionListener 
    { 
     public MyFileChooser chooser; 
     public MainFrame() 
     { 
      super("Main Frame"); 
      setDefaultCloseOperation(EXIT_ON_CLOSE); 
      try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} 
      catch(Exception e){ System.out.println("Unable to load Windows look and feel");} 
      setPreferredSize(new Dimension(300, 100)); 
      ((JPanel) getContentPane()).setBorder(new EmptyBorder(13, 13, 13, 13)); 
      setLayout(new FlowLayout()); 
      JButton btn = new JButton("Open"); 
      btn.setActionCommand("myButton"); 
      btn.addActionListener(this); 
      add(btn); 
      JPanel panel = new JPanel(); 

      chooser = new MyFileChooser("aaa", "The Title"); 
      chooser.setAcceptAllFileFilterUsed(false); 
      chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 
      chooser.setFileHidingEnabled(false); 

      pack(); 
      setLocationRelativeTo(null); 
      setVisible(true); 
      setResizable(false); 
     } 
     public void actionPerformed(ActionEvent e) 
     { 
      if(e.getActionCommand().equals("myButton")) 
      { 
       int status = chooser.showOpenDialog(null); 
       // blah blah 
      } 
     } 
     public static void main(String[] args) 
     { 
      new MainFrame(); 
     } 
    } 

はまた、私は次の解決策について考えたが、それは影響を与えませんでした:

JScrollBar scr = new JScrollBar(); 
scr.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
UIManager.put("JScrollPane.ScrollBar", scr); 
+0

かもしれhttp://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingaJFileChooserLookandFeel.htmとhttp://www.java2s.com/Tutorial/Java/0240__Swing/1260__JFileChooser.htmて、http: //www.java2s.com/Tutorial/Java/0240__Swing/LocalizeaJFileChooser.htm – mKorbel

答えて

1

.... JFileChooserPropertyChangeListenerを追加すると、isVisible();をリスニングすることができます。またはisDisplayable ...そしてJComponents JFileChooser(複合コンポーネント)を抽出し、getMyComponents()を呼び出します。

private void getMyComponents() { 
    Component findList = getJList(chooser); 
    JList myList = (JList) findList; 
    //find fileName in the JList and move with ViewPort view to the expected Rectangle 
    Component myScrollPane = getJScrollPane(chooser); 
    JScrollPane scrollPane = (JScrollPane) myScrollPane; 
    JViewport vport = scrollPane.getViewport(); 
    //move with ViewPort view to the expected Rectangle 
} 

private Component getJList(Component comp) { 
    if (comp.getClass() == JList.class) { 
     return comp; 
    } 
    if (comp instanceof Container) { 
     Component[] components = ((Container) comp).getComponents(); 
     for (int i = 0; i < components.length; i++) { 
      Component child = getJList(components[i]); 
      if (child != null) { 
       return child; 
      } 
     } 
    } 
    return null; 
} 

private Component getJScrollPane(Component comp) { 
    if (comp.getClass() == JScrollPane.class) { 
     return comp; 
    } 
    if (comp instanceof Container) { 
     Component[] components = ((Container) comp).getComponents(); 
     for (int i = 0; i < components.length; i++) { 
      Component child = getJScrollPane(components[i]); 
      if (child != null) { 
       return child; 
      } 
     } 
    } 
    return null; 
} 
1

あなた電話をしようとするUIManager.put("JScrollPane.ScrollBar", scr);良いです。私は、FileChooserがこの設定を無効にするか、この呼び出しを実行する前に作成されているため、動作しなかったと思います。

JContainerとしてファイルを作成した後で、ファイルセレクタを「発見」しようとお勧めします。スクロールバー(またはおそらくJScrollPane)を探してapplyComponentOrientationに電話してください。 私はこれをまだ試していませんが、すぐにそのような機能が必要になるので、これがあなたのために働いているかどうかを知ってうれしいです。

幸運。

関連する問題