Не удаётся сменить с Nimbus LookAndFeel - Java
Формулировка задачи:
Итак, суть проблемы в следующем: я хочу изменить вид нимбуса на вид шиндовса (по умолчанию стоит металл). Я в том месте, где происходит задание вида нимбусу написал javax.swing.UImanager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); однако это эффекта не возымело. После полуторачасового чтения документации я... Совершенно ничего не понял, потому что исходя из того, что в этой самой документации написано я делаю всё правильно, но не работает! Ах, что же делать, как же быть?
Решение задачи: «Не удаётся сменить с Nimbus LookAndFeel»
textual
Листинг программы
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package apackage;
- import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
- import javax.swing.plaf.basic.*;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- /**
- *
- * @author 123
- */
- public class main_frame extends javax.swing.JFrame {
- /**
- * Creates new form main_frame
- */
- public main_frame() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jMenuItem1 = new javax.swing.JMenuItem();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jLabel1 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- jMenu2 = new javax.swing.JMenu();
- jMenu4 = new javax.swing.JMenu();
- jMenuItem3 = new javax.swing.JMenuItem();
- jMenuItem4 = new javax.swing.JMenuItem();
- jMenu3 = new javax.swing.JMenu();
- jMenuItem2 = new javax.swing.JMenuItem();
- jMenuItem1.setText("jMenuItem1");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("1");
- setAlwaysOnTop(true);
- setLocation(new java.awt.Point(100, 100));
- setLocationByPlatform(true);
- setResizable(false);
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- jLabel1.setText("2");
- jButton1.setText("D");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("3");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("S");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jButton4.setText("B");
- jButton5.setText("E");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jButton6.setText("R");
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jMenu1.setText("0");
- jMenuBar1.add(jMenu1);
- jMenu2.setText("9");
- jMenu4.setText("84");
- jMenuItem3.setText("7");
- jMenu4.add(jMenuItem3);
- jMenuItem4.setText("19");
- jMenu4.add(jMenuItem4);
- jMenu2.add(jMenu4);
- jMenuBar1.add(jMenu2);
- jMenu3.setText("55");
- jMenuItem2.setText("654");
- jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem2ActionPerformed(evt);
- }
- });
- jMenu3.add(jMenuItem2);
- jMenuBar1.add(jMenu3);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
- .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
- .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
- JOptionPane.showMessageDialog(rootPane, "643", "76576", JOptionPane.NO_OPTION);
- }//GEN-LAST:event_jMenuItem2ActionPerformed
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
- label:{
- try {
- BufferedReader br2 = new BufferedReader(new FileReader("C:/Windows/Temp/65654"));
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(rootPane, "fd", "rqweq", JOptionPane.ERROR_MESSAGE);
- break label;
- }
- try {
- BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/e534342"));
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(rootPane, "6577777", "999", JOptionPane.ERROR_MESSAGE);
- break label;
- }
- new exps().setVisible(true);
- }
- }//GEN-LAST:event_jButton5ActionPerformed
- public int msf;
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
- label:{try {
- try {
- BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/mrewq"));
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(rootPane, "fas.", "hdfsaa", JOptionPane.ERROR_MESSAGE);
- break label;
- }
- try {
- BufferedReader br = new BufferedReader(new FileReader("C:/Windows/Temp/azvbb"));
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(rootPane, "le.", "dfsvcror!", JOptionPane.ERROR_MESSAGE);
- break label;
- }
- Thread.sleep(2000);
- String a, b, c, d, e, f, g, h, toadd;
- a = "\n";
- b = ".\n";
- c = "y\n";
- d = "...\n";
- e = "..\n";
- f = "Prt...\n";
- g = "Stfgrver\n";
- h = "M]\n";
- toadd = a+b+c+d+e+f+g+h;
- String bilo, stalo, dobavili = null;
- bilo = jTextArea1.getText();
- dobavili = toadd;
- stalo = bilo+dobavili;
- jTextArea1.setText(stalo);
- msf = 1;
- } catch (InterruptedException ex) {
- Logger.getLogger(main_frame.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }//GEN-LAST:event_jButton6ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- if(JOptionPane.showInputDialog(rootPane, "Speytr:").equals("rtewetr")){
- JOptionPane.showMessageDialog(rootPane, "Pfasfasd.", "Easfdsf", JOptionPane.ERROR_MESSAGE);
- }
- else{
- JOptionPane.showMessageDialog(rootPane, "N342.", "E34232!", JOptionPane.ERROR_MESSAGE);
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- new sca().setVisible(true);
- /* if(scaner.scanning){
- } */
- }//GEN-LAST:event_jButton2ActionPerformed
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
- for(UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()){
- JOptionPane.showMessageDialog(null, info.getName()+"\n"+info.getClassName()+"\n"+javax.swing.UIManager.getSystemLookAndFeelClassName());
- break;
- }
- }//GEN-LAST:event_jButton3ActionPerformed
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see [url]http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html[/url]
- */
- try {
- for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- break;
- }
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(main_frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(() -> {
- main_frame main = new main_frame();
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
- Logger.getLogger(main_frame.class.getName()).log(Level.SEVERE, null, ex);
- }
- SwingUtilities.updateComponentTreeUI(main);
- main.setVisible(true);
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenu jMenu3;
- private javax.swing.JMenu jMenu4;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JMenuItem jMenuItem3;
- private javax.swing.JMenuItem jMenuItem4;
- private javax.swing.JScrollPane jScrollPane1;
- public javax.swing.JTextArea jTextArea1;
- // End of variables declaration//GEN-END:variables
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д