Autor Tópico: Não consigo compilar programas com a aparecia do ubuntu no NetBeans (Resolvido)  (Lida 4019 vezes)

Offline brunnux

  • Usuário Ubuntu
  • *
  • Mensagens: 115
    • Ver perfil
Estou usando o NetBeans para aprender java na faculdade. Tudo bem até ai. Crio o jFrame e adiciono os componentes normalmente. Quando eu clico em Visualizar desenho: http://ubuntuone.com/p/O33/, a o programa aparece com a aparência nativa do ubuntu, o tema que eu estou usando: http://ubuntuone.com/p/O34/. Porem quando eu aperto o botão F6 para compilar e executar a aparência do programa fica assim: http://ubuntuone.com/p/O32/. Já procurei em vários sites e parece que tem a ver com Look and Feel, mas nada do que eu encontrei funcionou até agora.
« Última modificação: 29 de MAR?O de 2011, 10:51 por brunnux »

Offline glilco

  • Usuário Ubuntu
  • *
  • Mensagens: 80
  • Glilco Caneca
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #1 Online: 09 de Novembro de 2010, 01:39 »
brunnux, nunca utilizei o NetBeans ne sou um expert em interfaces Java, mas quase todos os programas em Java com interface gráfica que eu vejo ficam com esse aspecto "esquisitinho" mesmo.

Offline f_Candido

  • Usuário Ubuntu
  • *
  • Mensagens: 8
  • Compartilhar conhecimentos!!!
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #2 Online: 05 de Dezembro de 2010, 01:28 »
Opa,

Olá, você está usando Swing? SWT?


Abraços e posta mais informações para que possamos ajudá-lo.
Fagner Candido
Bacharelando em Ciência da Computação

Offline brunnux

  • Usuário Ubuntu
  • *
  • Mensagens: 115
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #3 Online: 30 de Dezembro de 2010, 22:16 »
Opa,

Desculpa a demora na resposta, tava meio ocupado.

Bom, eu to usando swing e uso o NetBeans no Ubuntu 10.10.

Se precisar de mais informações é só falar.

Offline GuilhermeSalazar

  • Usuário Ubuntu
  • *
  • Mensagens: 44
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #4 Online: 31 de Dezembro de 2010, 02:12 »
Olá amigo!

Adicione a seguinte linha de código ao método main:

Código: [Selecionar]
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Como você pode ver, o método setLookAndFeel recebe como argumento uma String que é o nome da classe que representa o visual.

Lembrando que esse código deve estar dentro de um try com os respectivos catches.

No final deve ficar mais ou menos assim:

Código: [Selecionar]
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (IllegalAccessException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

Offline brunnux

  • Usuário Ubuntu
  • *
  • Mensagens: 115
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #5 Online: 31 de Dezembro de 2010, 21:10 »
vou postar um codigo de um programa atoa aki. Tentei mais não funcionou.

Citar
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.text.DecimalFormat;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/*
 * Principal.java
 *
 * Created on 27/12/2010, 10:08:49
 */

/**
 *
 * @author barbara
 */
public class Principal extends javax.swing.JFrame {

    /** Creates new form Principal */
    public Principal() {
        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">                         
    private void initComponents() {

        qtf = new javax.swing.JTextField();
        vutf = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Somador de Balanço");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        qtf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                qtfActionPerformed(evt);
            }
        });

        vutf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vutfActionPerformed(evt);
            }
        });

        jLabel1.setText("Quant.");

        jLabel2.setText("Valor unit.");

        jLabel3.setText("Ultimos valores digitados:");

        jLabel4.setText("Valor total:");

        jMenu1.setText("Menu");

        jMenuItem2.setText("Zerar valores");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem1.setText("Sobre");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(qtf, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(vutf, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(202, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(qtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vutf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                       
    double tot=0, qt=1;

    DecimalFormat decimal = new DecimalFormat("0.00");
    DecimalFormat decimal1 = new DecimalFormat("0");

    sobre sob = new sobre();

    private void vutfActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
   double vl=0, vlp=0, a;
        String uvu, uvq, uvt, uvtg;

        try{
            vl=Double.parseDouble(vutf.getText());

            a=qt*vl;
            tot=tot+a;

            uvu=decimal1.format(qt);
            uvq=decimal.format(vl);
            uvt=decimal.format(a);
            uvtg=decimal.format(tot);

            jLabel3.setText("Ultimos valores digitados: "+uvu +" x "+uvq +" = " +uvt);
            jLabel4.setText("Valor total: "+uvtg);

            qtf.setText(null);
            vutf.setText(null);

            qt=1;

            qtf.requestFocus();

        }catch(NumberFormatException ex){
            JOptionPane.showMessageDialog(null,"\"Valor unit.\" preenchido incorretamente");
            vutf.setText(null);
            vutf.requestFocus();
        }
    }                                   

    private void qtfActionPerformed(java.awt.event.ActionEvent evt) {                                   
        // TODO add your handling code here:
        try{
            qt=Double.parseDouble(qtf.getText());
            vutf.requestFocus();
           
        }catch(NumberFormatException ex){
            qtf.setText("1");
            qt=Double.parseDouble(qtf.getText());
            vutf.requestFocus();
        }
       
    }                                   

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        sob.show();
    }                                         

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
       
    }                                         

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JTextField qtf;
    private javax.swing.JTextField vutf;
    // End of variables declaration                   

}

Offline GuilhermeSalazar

  • Usuário Ubuntu
  • *
  • Mensagens: 44
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #6 Online: 31 de Dezembro de 2010, 22:39 »
Como você fez?
Colocou da forma como falei, no método main?

Upe todo o projeto do NetBeans para que eu possa ver.

Offline GuilhermeSalazar

  • Usuário Ubuntu
  • *
  • Mensagens: 44
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #7 Online: 31 de Dezembro de 2010, 22:42 »
Acabei de testar aqui, com teu código e deu certo.
Observe como ficou o método main:

Código: [Selecionar]
public static void main(String args[]) {
     try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

Offline brunnux

  • Usuário Ubuntu
  • *
  • Mensagens: 115
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #8 Online: 01 de Janeiro de 2011, 11:45 »
Hahaahaha!

GuilhermeSalazar, nem meu professor de java doutorado em IA conseguiu resolver esse problema.
Já estava a meses procurando os professores do campus e tudo que eles me falavam é que "a idéia do Java é que ele não seja dependente do SO, por isso ele tem essa interface própria".
Eu sabia que tinha como fazer pq eu já vi aplicativos Java com a aparência do SO.

Devo ter feito algo errado da ultima vez que testei, mas dessa vez funcionou.

Muito obrigado cara.

Offline GuilhermeSalazar

  • Usuário Ubuntu
  • *
  • Mensagens: 44
    • Ver perfil
Re: Não consigo compilar programas com a aparecia do ubuntu no NetBeans
« Resposta #9 Online: 01 de Janeiro de 2011, 14:39 »
brunnux,
que bom que funcinou!

Um abraço.