2012-11-30 49 views
0

我創建與NetBeans中的MDI應用程序不使用JFrame的L&F,一切的工作以及與預期的外觀和感覺設置爲雨雲。的JInternalFrame在Netbeans的7.1.2

當我運行應用程序時,JFrame及其工具欄使用指定的L & F(Nimbus),但內部框架使用跨平臺(金屬)L使應用程序看起來很破舊。

我想要的內框使用相同的大號& F作爲JFrame中。請如何解決此問題?

我已經打過電話JFrame.setdefaultlookandfeeldecorated(true)SwingUtilities.updatecomponenttreeui(frame)但他們並沒有解決問題。

+4

1)爲了更好地幫助越早,張貼[ SSCCE](http://sscce.org/)。 2)*「我嘗試過調用'SwingUtilities.updatecomponenttreeui(frame)',但它們沒有解決問題。」*那不會編譯。 –

+0

@AndrewThompson我的意思是JFrame.setDefaultLookAndFeelDecorated(true)和SwingUtilities.updateComponentTreeUi(框架)。代碼編譯但不解決問題。 –

+0

很好,你注意到了第二點。現在參加第一場。 ;) –

回答

2

每當我運行應用程序,JFrame中和它的工具欄使用 L尺寸指定& F(靈氣),但內部框架採用跨平臺 (金屬)長&˚F使應用程序顯得寒酸。

enter image description here

import java.awt.Dimension; 
import java.awt.EventQueue; 
import javax.swing.*; 
import javax.swing.UIManager.LookAndFeelInfo; 

public class TestInternalFrame { 

    public TestInternalFrame() { 
     final JInternalFrame internal = new JInternalFrame("test"); 
     final JInternalFrame hidden = new JInternalFrame("test"); 
     hidden.setBounds(1000, 1000, 1, 1); 
     hidden.setVisible(true); 
     internal.setVisible(true); 
     internal.setBounds(0, 0, 100, 100); 
     JDesktopPane pane = new JDesktopPane(); 
     pane.add(internal); 
     pane.add(hidden); 
     pane.setPreferredSize(new Dimension(10000, 10000)); 
     final JFrame frame = new JFrame("Test"); 
     frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
     frame.getContentPane().add(new JScrollPane(pane, 
       JScrollPane.VERTICAL_SCROLLBAR_NEVER, 
       JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); 
     /*frame.getContentPane().add(new JButton(new AbstractAction("Show blocked dialog") { 

     private static final long serialVersionUID = 1L; 

     @Override 
     public void actionPerformed(ActionEvent e) { 
     EventQueue.invokeLater(new Runnable() { 

     @Override 
     public void run() { 
     JOptionPane.showInternalMessageDialog(hidden, "Hi 2!"); 
     } 
     }); 
     JOptionPane.showInternalMessageDialog(internal, "Hi 1!"); 
     } 
     }), BorderLayout.PAGE_END);*/ 
     frame.setPreferredSize(new Dimension(400, 300)); 
     frame.pack(); 
     frame.setLocationRelativeTo(null); 
     frame.setVisible(true); 
    } 

    public static void main(String[] args) { 
     try { 
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 
       System.out.println(info.getName()); 
       if ("Nimbus".equals(info.getName())) { 
        UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
     } catch (UnsupportedLookAndFeelException e) { 
      // handle exception 
     } catch (ClassNotFoundException e) { 
      // handle exception 
     } catch (InstantiationException e) { 
      // handle exception 
     } catch (IllegalAccessException e) { 
      // handle exception 
     } 

     EventQueue.invokeLater(new Runnable() { 

      @Override 
      public void run() { 
       TestInternalFrame tif = new TestInternalFrame(); 
      } 
     }); 
    } 
} 
+0

@mrKorbel感謝了很多,這是非常相似,我有,NetBeans在外觀和感覺你的代碼,但不加JFrame.setDefaultLookAndFeelDecorated(真)和SwingUtilities.updateComponentTreeUi(幀)。我最初認爲這可能是問題,但即使在添加它們之後,它也沒有解決問題。也許它是Netbeans。 Lol –

+0

我也嘗試將L&F更改爲LiquidLookAndFeel,JFrame的L&F改變得相當好,但內部框架仍然卡在Metal L&F上。 –

+0

@Jide Kolade只有[物質](http://stackoverflow.com/a/10909869/714968)可以做到這一點(正確和恰當的方式),以改變JFrames descorations(通知來自於原生操作系統應用於當前主題) – mKorbel

相關問題