[英]System look and feel layout on JFileChooser but with nimbus look and feel theme
JFileChooser上的窗口外觀和感覺布局比其他外觀好很多,感覺就像靈氣。
所以我正在尋找一種方法來獲得系統外觀和感覺的布局,但在頂部有nimbus或其他主題。
這可能嗎? 如果是這樣,怎么辦呢?
這是可能的,雖然我不知道是否推薦。 我設法通過要求視圖在除了最頂層的JFileChooser組件之外的所有組件上更新自己來實現它(因為這將用你不想要的Nimbus組件替換所有選擇器組件)。
我認為這可能會或可能不會起作用,具體取決於Windows外觀的內部結構。 它幾乎依賴於由Swing組件構建的整個JFileChooser。 如果它被更改為使用更直接的本機渲染(即Java要求Windows繪制選擇器的重要部分),它將無法工作。 不知道這個技巧與其他組件的效果如何。
無論如何,這段代碼似乎適用於JDK 7:
package test;
import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.plaf.nimbus.NimbusLookAndFeel; //Or use com.sun.... if you are using JDK < 7
public class LAFTester
{
public static void main(String... args)
throws Exception
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFileChooser chooser = new JFileChooser();
chooser.updateUI(); //Create UI objects
UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName()); //Now set look and feel
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); //works with metal as well
refreshUI(chooser, false);
chooser.showOpenDialog(null);
}
private static void refreshUI(JComponent c, boolean includeParent)
{
if (includeParent)
c.updateUI();
for (int i = 0; i < c.getComponentCount(); i++)
{
Component child = c.getComponent(i);
if (child instanceof JComponent)
{
refreshUI((JComponent)child, true);
}
}
}
}
我假設您正在討論Windows文件選擇器對話框左側的面板,其中包含Desktop
, My Computer
My Documents
圖標?
好吧,我懷疑這可以做到,因為這是特定於LAF的。 這被添加到Windows LAF中,因為這是Windows平台文件選擇的樣子。 它不支持其他LAF。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.