2010-03-23 12 views
2

je suis nouveau à netbeans ide, j'ai une application de bureau de balançoire et je veux changer l'aspect et la sensation java par défaut pour l'aspect de substance (ou autre), donc comment ajouter le fichier jar de substance à mon projet (je veux déployer le projet dans le fichier jar), et définir un aspect et une sensation de celui-ci.comment changer l'aspect et la sensation de swing dans netbeans

grâce

+0

Que devez-vous faire exactement? Vous avez besoin de changer l'apparence de l'IDE ou de votre application? Si IDE - alors pourquoi? –

Répondre

3

Vous placez le .jar dans un emballage de module, comme vous le feriez pour tout fichier .jar dans une application plate-forme NetBeans. En ce qui concerne la mise en l'apparence, vous voudrez peut-être étendre ModuleInstall, en particulier, remplacer la méthode restaurée() avec quelque chose comme ceci:

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

d'abord essayer ce code:

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); 


    } 
} 

Vous pouvez également utiliser le thème Nimbus, modifié à ce code:

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

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

et modifier le projet principal pour ceci:

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); 


} 

Référence: forum.codecall.net

0

Si vous voulez utiliser la substance LookAndFeel dans votre application, l'étape facile est d'ajouter pot SubstanceLookAndFeel dans votre classpath de bibliothèque (sur NetBeans IDE juste un clic droit sur le nœud bibliothèque, puis ajoutez Substance.jar). Après avoir ajouté substance.jar, dans l'application principale il suffit d'ajouter ce code (avant de lancer cadre principal):

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(); 
     } 
    }); 
} 

Si vous voulez NetBeans IDE en utilisant Look Substance Et Sentez-vous aussi, il suffit de mettre SubstanceLookAndFeel.jar dans le répertoire spécifique (. ex à /home/your-username/LAF/SubstanceLookAndFeel.jar) et lancer NetBeans IDE avec cette commande:

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

Désolé si est vieux mais sur Netbeans vous pouvez cliquer avec le bouton secondaire sur votre projet (clic droit), et allez à Propriétés.

Suivant aller à Appliation> Desktop App et là, vous pouvez changer l'aspect :).