2011-02-13 157 views
4

我一直在製作一個使用JFileChooser的程序。我已經設置了應用了有沒有辦法在Ubuntu下改進JFileChooser的外觀和感覺?

UIManager.getSystemLookAndFeelClassName()

這只是正常的Ubuntu下幾乎一切。到目前爲止唯一遇到的問題是JFileChooser出來看起來很糟糕: JFileChooser with SystemLookAndFeel

有沒有辦法讓它看起來像Ubuntu中的默認文件選擇器?即。 Desired file chooser dialog

我使用

UIManager.getCrossPlatformLookAndFeelClassName()

這使得JFileChooser對話框的外觀更好試過了,但仍然沒有本土來看,它破壞了其餘關閉應用程序的感覺也是如此。

謝謝。

+0

參考下鏈路的溶液: http://stackoverflow.com/questions/10597831/improving-jfilechooser- under-ubuntu-12-04-gtk – 2013-04-26 19:41:36

回答

2

如果我沒有記錯,股票JDK使用gtk1,但ubuntu當前使用gtk2。我忘了在哪裏,但我已經在某處遇到了gtk2 for java。谷歌?可能不是你所希望的,對不起。

+0

搜索這個確實有幫助,我碰到了這個:https://code.google.com/p/gtkjfilechooser/。不知道我如何使這個跨平臺執行,但我會更多地考慮它。謝謝你的幫助。 – joshschreuder 2011-02-14 04:18:00

+0

你可能會做jzd建議你用nimbus做的事,並將它作爲你項目中的一個獨立的lib添加,並且只在需要gtk本機外觀的系統上使用。 – jwp 2011-02-15 11:46:15

1

靈氣的外觀和感覺有一個體面的文件選擇。雖然這會影響你的整個應用程序,但你可能會喜歡它的外觀。

如果需要,你也可以建立自己的文件選擇器。

0

你也可以用SWT代替swing。

Does Swing support Windows 7-style file choosers?

下面的代碼是從上方連結

import org.eclipse.swt.*; 
import org.eclipse.swt.widgets.*; 

public class SWTFileOpenSnippet { 
    public static void main (String [] args) { 
     Display display = new Display(); 
     Shell shell = new Shell (display); 
     // Don't show the shell. 
     //shell.open(); 
     FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI); 
     String [] filterNames = new String [] {"All Files (*)"}; 
     String [] filterExtensions = new String [] {"*"}; 
     String filterPath = "c:\\"; 
     dialog.setFilterNames (filterNames); 
     dialog.setFilterExtensions (filterExtensions); 
     dialog.setFilterPath (filterPath); 
     dialog.open(); 
     System.out.println ("Selected files: "); 
     String[] selectedFileNames = dialog.getFileNames(); 
     for(String fileName : selectedFileNames) { 
      System.out.println(" " + fileName); 
     } 
     shell.close(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) display.sleep(); 
     } 
     display.dispose(); 
    } 
}