e ai galera…
seguinte eu to com uns problemas com o swing aqui…toda vez que coloco pra executar algo, como por exemplo um progress bar (feito atraves do netbeans) ele fica tipo desabilitado sem poder fazer nada com o jframe…
peguei um exemplo de progress bar na internet e funcionou normal
o que pode ser?
[code]/*
- NewJFrame.java
-
- Created on 18 de Outubro de 2008, 16:44
*/
package javaapplication1;
import javax.swing.SwingUtilities;
/**
*
-
@author Jonny
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
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.
*/
//
private void initComponents() {
botao = new javax.swing.JButton();
pbar = new javax.swing.JProgressBar();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
botao.setText(“botao”);
botao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botaoActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(botao))
.addGroup(layout.createSequentialGroup()
.addGap(96, 96, 96)
.addComponent(pbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(158, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(149, Short.MAX_VALUE)
.addComponent(botao)
.addGap(38, 38, 38)
.addComponent(pbar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50))
);
pack();
}//
private void botaoActionPerformed(java.awt.event.ActionEvent evt) {
int minimo = 1;
int maximo = 5;
pbar.setMinimum(minimo);
pbar.setMaximum(maximo);
for (int i = minimo; i <= maximo; i++) {
final int percent = i;
try {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
pbar.setValue(percent);
}
});
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton botao;
private javax.swing.JProgressBar pbar;
// End of variables declaration
}
[/code]
Quando mexo com interfaces e vou fazer alguma tarefa, como acessar um banco ou algum processamento um pouco maior, coloco isso numa Thread separada para não ter esse problema de tratamento. Tente fazer o mesmo apra ver se nao da certo…