2010-03-23 47 views
2

我是netbeans ide的新手,我有一個擺動桌面應用程序,我想將默認的Java外觀(感覺)更改爲實體外觀(或其他),所以如何將物質jar文件添加到我的項目 (我想將項目部署到jar文件),並設置它的外觀和感覺。如何更改netbeans中的擺動外觀

感謝

+0

你到底需要做什麼?您需要更改IDE或應用程序的外觀?如果IDE - 那爲什麼? – 2010-03-23 09:19:17

回答

3

你放置的.jar在模塊封裝,就像在NetBeans平臺應用程序的任何.jar文件。至於設置的外觀和感覺,你可能要延長ModuleInstall,具體地講,像這樣的東西覆蓋恢復()方法:

try { 
     UIManager.setLookAndFeel(new SubstanceRavenGraphiteLookAndFeel()); 
    } catch (Exception e) { 
     System.out.println("Substance Raven Graphite failed to initialize"); 
    } 
4

第一次嘗試這樣的代碼:

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 

public class Test extends JFrame { 
public Test() { 
    initComponents(); 
} 

private void initComponents() { 
    // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents 
    menuBar1 = new JMenuBar(); 
    menu1 = new JMenu(); 
    menuItem5 = new JMenuItem(); 
    menuItem4 = new JMenuItem(); 
    checkBoxMenuItem1 = new JCheckBoxMenuItem(); 
    menuItem3 = new JMenuItem(); 
    menu2 = new JMenu(); 
    menuItem6 = new JMenuItem(); 
    tabbedPane1 = new JTabbedPane(); 
    panel1 = new JPanel(); 
    scrollPane1 = new JScrollPane(); 
    textPane1 = new JTextPane(); 
    button1 = new JButton(); 
    button2 = new JButton(); 
    button3 = new JButton(); 
    scrollPane2 = new JScrollPane(); 
    textArea1 = new JTextArea(); 
    scrollPane3 = new JScrollPane(); 
    tree1 = new JTree(); 
    progressBar1 = new JProgressBar(); 
    radioButton1 = new JRadioButton(); 
    checkBox1 = new JCheckBox(); 
    panel2 = new JPanel(); 
    panel3 = new JPanel(); 

    Container contentPane = getContentPane(); 
    contentPane.setLayout(null); 
    { 
     { 
      menu1.setText("text"); 
      menuItem5.setText("text"); 
      menu1.add(menuItem5); 
      menuItem4.setText("text"); 
      menu1.add(menuItem4); 
      menu1.addSeparator(); 
      checkBoxMenuItem1.setText("text"); 
      menu1.add(checkBoxMenuItem1); 
      menuItem3.setText("text"); 
      menu1.add(menuItem3); 
     } 
     menuBar1.add(menu1); 
     { 
      menu2.setText("text"); 
      menuItem6.setText("text"); 
      menu2.add(menuItem6); 
     } 
     menuBar1.add(menu2); 
    } 
    setJMenuBar(menuBar1); 
    { 

     { 
      panel1.setLayout(null); 

      { 
       scrollPane1.setViewportView(textPane1); 
      } 
      panel1.add(scrollPane1); 
      scrollPane1.setBounds(15, 15, 665, scrollPane1.getPreferredSize().height); 
      button1.setText("text"); 
      panel1.add(button1); 
      button1.setBounds(15, 45, 300, button1.getPreferredSize().height); 
      button2.setText("text"); 
      panel1.add(button2); 
      button2.setBounds(325, 45, 140, 23); 
      button3.setText("text"); 
      panel1.add(button3); 
      button3.setBounds(470, 45, 210, 23); 
      { 
       scrollPane2.setViewportView(textArea1); 
      } 
      panel1.add(scrollPane2); 
      scrollPane2.setBounds(15, 75, 665, 175); 
      { 
       scrollPane3.setViewportView(tree1); 
      } 
      panel1.add(scrollPane3); 
      scrollPane3.setBounds(15, 260, 140, 150); 
      progressBar1.setValue(40); 
      panel1.add(progressBar1); 
      progressBar1.setBounds(160, 260, 520, 20); 
      radioButton1.setText("text"); 
      panel1.add(radioButton1); 
      radioButton1.setBounds(160, 290, 100, radioButton1.getPreferredSize().height); 
      checkBox1.setText("text"); 
      panel1.add(checkBox1); 
      checkBox1.setBounds(265, 295, 165, checkBox1.getPreferredSize().height); 

      { 
       Dimension preferredSize = new Dimension(); 
       for(int i = 0; i < panel1.getComponentCount(); i++) { 
        Rectangle bounds = panel1.getComponent(i).getBounds(); 
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 
       } 
       Insets insets = panel1.getInsets(); 
       preferredSize.width += insets.right; 
       preferredSize.height += insets.bottom; 
       panel1.setMinimumSize(preferredSize); 
       panel1.setPreferredSize(preferredSize); 
      } 
     } 
     tabbedPane1.addTab("text", panel1); 
     { 
      panel2.setLayout(null); 

      { 
       Dimension preferredSize = new Dimension(); 
       for(int i = 0; i < panel2.getComponentCount(); i++) { 
        Rectangle bounds = panel2.getComponent(i).getBounds(); 
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 
       } 
       Insets insets = panel2.getInsets(); 
       preferredSize.width += insets.right; 
       preferredSize.height += insets.bottom; 
       panel2.setMinimumSize(preferredSize); 
       panel2.setPreferredSize(preferredSize); 
      } 
     } 
     tabbedPane1.addTab("text", panel2); 

     { 
      panel3.setLayout(null); 

      { 
       Dimension preferredSize = new Dimension(); 
       for(int i = 0; i < panel3.getComponentCount(); i++) { 
        Rectangle bounds = panel3.getComponent(i).getBounds(); 
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 
       } 
       Insets insets = panel3.getInsets(); 
       preferredSize.width += insets.right; 
       preferredSize.height += insets.bottom; 
       panel3.setMinimumSize(preferredSize); 
       panel3.setPreferredSize(preferredSize); 
      } 
     } 
     tabbedPane1.addTab("text", panel3); 

    } 
    contentPane.add(tabbedPane1); 
    tabbedPane1.setBounds(10, 10, 700, 450); 

    { 
     Dimension preferredSize = new Dimension(); 
     for(int i = 0; i < contentPane.getComponentCount(); i++) { 
      Rectangle bounds = contentPane.getComponent(i).getBounds(); 
      preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 
      preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 
     } 
     Insets insets = contentPane.getInsets(); 
     preferredSize.width += insets.right; 
     preferredSize.height += insets.bottom; 
     contentPane.setMinimumSize(preferredSize); 
     contentPane.setPreferredSize(preferredSize); 
    } 
    pack(); 
    setLocationRelativeTo(getOwner()); 

} 

private JMenuBar menuBar1; 
private JMenu menu1; 
private JMenuItem menuItem5; 
private JMenuItem menuItem4; 
private JCheckBoxMenuItem checkBoxMenuItem1; 
private JMenuItem menuItem3; 
private JMenu menu2; 
private JMenuItem menuItem6; 
private JTabbedPane tabbedPane1; 
private JPanel panel1; 
private JScrollPane scrollPane1; 
private JTextPane textPane1; 
private JButton button1; 
private JButton button2; 
private JButton button3; 
private JScrollPane scrollPane2; 
private JTextArea textArea1; 
private JScrollPane scrollPane3; 
private JTree tree1; 
private JProgressBar progressBar1; 
private JRadioButton radioButton1; 
private JCheckBox checkBox1; 
private JPanel panel2; 
private JPanel panel3; 

public static void main(String args[]){ 

    new Test().setVisible(true); 


    } 
} 

你也可以使用Nimbus的主題,修改這個代碼:

try{ 
     UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 

    } 
    catch(Exception e){ 
     System.out.println("Nimbus isn't available"); 
    } 

和編輯這個主要項目:

public static void main(String args[]){ 

    try{ 
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 

    } 
    catch(Exception e){ 
     System.out.println("Nimbus isn't available"); 
    } 
    new Test().setVisible(true); 


} 

參考: forum.codecall.net

0

如果你想使用物質的LookAndFeel在你的應用程序中,簡單的步驟是添加SubstanceLookAndFeel罐子到你的庫類路徑(在NetBeans IDE的庫節點上剛剛點擊右鍵,然後加入Substance.jar )。添加在主應用程序substance.jar後,只需添加以下代碼(在啓動主框架前):如果您在使用物質看看要NetBeans IDE中

public static void main(String[] args) { 
    java.awt.EventQueue.invokeLater(new Runnable() { 

     @Override 
     public void run() { 
      try { 
       UIManager.setLookAndFeel(new SubstanceLookAndFeel()); 
      } catch (ClassNotFoundException ex) { 
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (InstantiationException ex) { 
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (IllegalAccessException ex) { 
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (UnsupportedLookAndFeelException ex) { 
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
      } 
      new MainFrame(); 
     } 
    }); 
} 

,感受得,只是把SubstanceLookAndFeel.jar在特定目錄(在/home/your-username/LAF/SubstanceLookAndFeel.jar前),並啓動NetBeans IDE,使用此命令:

$ netbeans --cp:p /home/your-username/LAF/SubstanceLookAndFeel.jar --laf org.jvnet.substance.SubstanceLookAndFeel 
1

很抱歉,如果是舊的,但在Netbeans中您可以使用輔助按鈕點擊您的項目(右鍵單擊),然後轉到「屬性」。

下一步去Appliation>桌面應用程序,那裏你可以改變外觀和感覺:)。