Не удаётся сменить с Nimbus LookAndFeel - Java

Узнай цену своей работы

Формулировка задачи:

Итак, суть проблемы в следующем: я хочу изменить вид нимбуса на вид шиндовса (по умолчанию стоит металл). Я в том месте, где происходит задание вида нимбусу написал javax.swing.UImanager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); однако это эффекта не возымело. После полуторачасового чтения документации я... Совершенно ничего не понял, потому что исходя из того, что в этой самой документации написано я делаю всё правильно, но не работает! Ах, что же делать, как же быть?

Решение задачи: «Не удаётся сменить с Nimbus LookAndFeel»

textual
Листинг программы
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package apackage;
  7. import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
  8. import javax.swing.plaf.basic.*;
  9. import java.io.BufferedReader;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileReader;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.SwingUtilities;
  16. import javax.swing.UIManager;
  17. import javax.swing.UnsupportedLookAndFeelException;
  18.  
  19. /**
  20.  *
  21.  * @author 123
  22.  */
  23. public class main_frame extends javax.swing.JFrame {
  24.  
  25.     /**
  26.      * Creates new form main_frame
  27.      */
  28.     public main_frame() {
  29.         initComponents();
  30.     }
  31.  
  32.     /**
  33.      * This method is called from within the constructor to initialize the form.
  34.      * WARNING: Do NOT modify this code. The content of this method is always
  35.      * regenerated by the Form Editor.
  36.      */
  37.     @SuppressWarnings("unchecked")
  38.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  39.     private void initComponents() {
  40.  
  41.         jMenuItem1 = new javax.swing.JMenuItem();
  42.         jScrollPane1 = new javax.swing.JScrollPane();
  43.         jTextArea1 = new javax.swing.JTextArea();
  44.         jLabel1 = new javax.swing.JLabel();
  45.         jButton1 = new javax.swing.JButton();
  46.         jButton2 = new javax.swing.JButton();
  47.         jButton3 = new javax.swing.JButton();
  48.         jButton4 = new javax.swing.JButton();
  49.         jButton5 = new javax.swing.JButton();
  50.         jButton6 = new javax.swing.JButton();
  51.         jMenuBar1 = new javax.swing.JMenuBar();
  52.         jMenu1 = new javax.swing.JMenu();
  53.         jMenu2 = new javax.swing.JMenu();
  54.         jMenu4 = new javax.swing.JMenu();
  55.         jMenuItem3 = new javax.swing.JMenuItem();
  56.         jMenuItem4 = new javax.swing.JMenuItem();
  57.         jMenu3 = new javax.swing.JMenu();
  58.         jMenuItem2 = new javax.swing.JMenuItem();
  59.  
  60.         jMenuItem1.setText("jMenuItem1");
  61.  
  62.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  63.         setTitle("1");
  64.         setAlwaysOnTop(true);
  65.         setLocation(new java.awt.Point(100, 100));
  66.         setLocationByPlatform(true);
  67.         setResizable(false);
  68.  
  69.         jTextArea1.setColumns(20);
  70.         jTextArea1.setRows(5);
  71.         jScrollPane1.setViewportView(jTextArea1);
  72.  
  73.         jLabel1.setText("2");
  74.  
  75.         jButton1.setText("D");
  76.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  77.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  78.                 jButton1ActionPerformed(evt);
  79.             }
  80.         });
  81.  
  82.         jButton2.setText("3");
  83.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  84.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  85.                 jButton2ActionPerformed(evt);
  86.             }
  87.         });
  88.  
  89.         jButton3.setText("S");
  90.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  91.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  92.                 jButton3ActionPerformed(evt);
  93.             }
  94.         });
  95.  
  96.         jButton4.setText("B");
  97.  
  98.         jButton5.setText("E");
  99.         jButton5.addActionListener(new java.awt.event.ActionListener() {
  100.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                 jButton5ActionPerformed(evt);
  102.             }
  103.         });
  104.  
  105.         jButton6.setText("R");
  106.         jButton6.addActionListener(new java.awt.event.ActionListener() {
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  108.                 jButton6ActionPerformed(evt);
  109.             }
  110.         });
  111.  
  112.         jMenu1.setText("0");
  113.         jMenuBar1.add(jMenu1);
  114.  
  115.         jMenu2.setText("9");
  116.  
  117.         jMenu4.setText("84");
  118.  
  119.         jMenuItem3.setText("7");
  120.         jMenu4.add(jMenuItem3);
  121.  
  122.         jMenuItem4.setText("19");
  123.         jMenu4.add(jMenuItem4);
  124.  
  125.         jMenu2.add(jMenu4);
  126.  
  127.         jMenuBar1.add(jMenu2);
  128.  
  129.         jMenu3.setText("55");
  130.  
  131.         jMenuItem2.setText("654");
  132.         jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
  133.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  134.                 jMenuItem2ActionPerformed(evt);
  135.             }
  136.         });
  137.         jMenu3.add(jMenuItem2);
  138.  
  139.         jMenuBar1.add(jMenu3);
  140.  
  141.         setJMenuBar(jMenuBar1);
  142.  
  143.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  144.         getContentPane().setLayout(layout);
  145.         layout.setHorizontalGroup(
  146.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  147.             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
  148.             .addGroup(layout.createSequentialGroup()
  149.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  150.                     .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  151.                     .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  152.                     .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
  153.                     .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  154.                     .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  155.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  156.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  157.                     .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
  158.                     .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  159.         );
  160.         layout.setVerticalGroup(
  161.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  162.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  163.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  164.                     .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
  165.                     .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  166.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  167.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  168.                     .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  169.                     .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
  170.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  171.                 .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
  172.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  173.                 .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
  174.                 .addGap(18, 18, 18)
  175.                 .addComponent(jLabel1)
  176.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  177.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
  178.         );
  179.  
  180.         pack();
  181.     }// </editor-fold>//GEN-END:initComponents
  182.  
  183.     private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
  184.         JOptionPane.showMessageDialog(rootPane, "643", "76576", JOptionPane.NO_OPTION);
  185.     }//GEN-LAST:event_jMenuItem2ActionPerformed
  186.  
  187.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
  188.         label:{            
  189.         try {
  190.             BufferedReader br2 = new BufferedReader(new FileReader("C:/Windows/Temp/65654"));            
  191.         } catch (FileNotFoundException ex) {
  192.             JOptionPane.showMessageDialog(rootPane, "fd", "rqweq", JOptionPane.ERROR_MESSAGE);
  193.             break label;
  194.         }
  195.         try {
  196.             BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/e534342"));            
  197.         } catch (FileNotFoundException ex) {
  198.             JOptionPane.showMessageDialog(rootPane, "6577777", "999", JOptionPane.ERROR_MESSAGE);
  199.             break label;
  200.         }
  201.         new exps().setVisible(true);
  202.         }
  203.     }//GEN-LAST:event_jButton5ActionPerformed
  204. public int msf;
  205.     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
  206.         label:{try {
  207.             try {
  208.             BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/mrewq"));
  209.             } catch (FileNotFoundException ex) {
  210.             JOptionPane.showMessageDialog(rootPane, "fas.", "hdfsaa", JOptionPane.ERROR_MESSAGE);
  211.             break label;
  212.             }
  213.             try {
  214.             BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/azvbb"));
  215.             } catch (FileNotFoundException ex) {
  216.             JOptionPane.showMessageDialog(rootPane, "le.", "dfsvcror!", JOptionPane.ERROR_MESSAGE);
  217.             break label;
  218.             }
  219.             Thread.sleep(2000);
  220.             String a, b, c, d, e, f, g, h, toadd;
  221.             a = "\n";
  222.             b = ".\n";
  223.             c = "y\n";
  224.             d = "...\n";
  225.             e = "..\n";
  226.             f = "Prt...\n";
  227.             g = "Stfgrver\n";
  228.             h = "M]\n";
  229.             toadd = a+b+c+d+e+f+g+h;
  230.             String bilo, stalo, dobavili = null;
  231.             bilo = jTextArea1.getText();
  232.             dobavili = toadd;
  233.             stalo = bilo+dobavili;
  234.             jTextArea1.setText(stalo);
  235.             msf = 1;
  236.             } catch (InterruptedException ex) {
  237.                 Logger.getLogger(main_frame.class.getName()).log(Level.SEVERE, null, ex);
  238.             }
  239.         }
  240.     }//GEN-LAST:event_jButton6ActionPerformed
  241.  
  242.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  243.         if(JOptionPane.showInputDialog(rootPane, "Speytr:").equals("rtewetr")){
  244.             JOptionPane.showMessageDialog(rootPane, "Pfasfasd.", "Easfdsf", JOptionPane.ERROR_MESSAGE);
  245.         }
  246.         else{
  247.             JOptionPane.showMessageDialog(rootPane, "N342.", "E34232!", JOptionPane.ERROR_MESSAGE);
  248.         }
  249.     }//GEN-LAST:event_jButton1ActionPerformed
  250.  
  251.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  252.         new sca().setVisible(true);
  253.        /* if(scaner.scanning){
  254.            
  255.         } */
  256.     }//GEN-LAST:event_jButton2ActionPerformed
  257.  
  258.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  259.         for(UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()){
  260.             JOptionPane.showMessageDialog(null, info.getName()+"\n"+info.getClassName()+"\n"+javax.swing.UIManager.getSystemLookAndFeelClassName());
  261.             break;
  262.         }
  263.     }//GEN-LAST:event_jButton3ActionPerformed
  264.    
  265.     /**
  266.      * @param args the command line arguments
  267.      */
  268.     public static void main(String args[]) {
  269.         /* Set the Nimbus look and feel */
  270.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  271.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  272.          * For details see [url]http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html[/url]
  273.          */
  274.         try {
  275.            for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  276.                 if ("Nimbus".equals(info.getName())) {
  277.                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  278.                     break;
  279.                 }
  280.            
  281.             }
  282.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
  283.             java.util.logging.Logger.getLogger(main_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  284.         }
  285.         //</editor-fold>
  286.        
  287.         //</editor-fold>
  288.  
  289.         /* Create and display the form */
  290.         java.awt.EventQueue.invokeLater(() -> {
  291.             main_frame main = new main_frame();
  292.             try {
  293.                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  294.             } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
  295.                 Logger.getLogger(main_frame.class.getName()).log(Level.SEVERE, null, ex);
  296.             }
  297.             SwingUtilities.updateComponentTreeUI(main);
  298.             main.setVisible(true);
  299.         });
  300.     }
  301.  
  302.     // Variables declaration - do not modify//GEN-BEGIN:variables
  303.     private javax.swing.JButton jButton1;
  304.     private javax.swing.JButton jButton2;
  305.     private javax.swing.JButton jButton3;
  306.     private javax.swing.JButton jButton4;
  307.     private javax.swing.JButton jButton5;
  308.     private javax.swing.JButton jButton6;
  309.     private javax.swing.JLabel jLabel1;
  310.     private javax.swing.JMenu jMenu1;
  311.     private javax.swing.JMenu jMenu2;
  312.     private javax.swing.JMenu jMenu3;
  313.     private javax.swing.JMenu jMenu4;
  314.     private javax.swing.JMenuBar jMenuBar1;
  315.     private javax.swing.JMenuItem jMenuItem1;
  316.     private javax.swing.JMenuItem jMenuItem2;
  317.     private javax.swing.JMenuItem jMenuItem3;
  318.     private javax.swing.JMenuItem jMenuItem4;
  319.     private javax.swing.JScrollPane jScrollPane1;
  320.     public javax.swing.JTextArea jTextArea1;
  321.     // End of variables declaration//GEN-END:variables
  322. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.625 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут