Tenho um projeto no eclipse e importei-o pro netbeans utilizando a opção IMPORT PROJECT/ECLIPSE PROJECT.
Até aí OK. Importou, executou e funcionou como no eclipse.
Porém, na parte de edição, mais especificamente das interfaces gráficas, não estou conseguindo abrir em modo Design.
Segue em anexo uma imagem de uma tela de consulta da aplicação, em que não mostra a opção de edição em modo Design.
Segue também o fonte da tela, por via das dúvidas:
package br.com.empresa.bairro;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import br.com.empresa.componentes.FrameInterno;
import br.com.empresa.conexao.Conexao;
import br.com.empresa.interfacesGraficas.MostraMsg;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JCheckBox;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.ListSelectionModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@SuppressWarnings("serial")
public class ConsBairro extends FrameInterno {
//private Conexao conexao = new Conexao();
private PreparedStatement prep;
public Boolean inicializado=false;
private JPanel panel = new JPanel();
private JTable tbBairro = new JTable();
private JScrollPane spTbBairro = new JScrollPane();
private JTextField txtBairro = new JTextField();
private JLabel lblBairro = new JLabel("Bairro");
private JButton btnAtualizarBusca = new JButton("");
private JButton btnAdicionar = new JButton("");
private JButton btnExcluir = new JButton("");
private JButton btnEditar = new JButton("");
private DefaultTableModel modelo = new DefaultTableModel(
new Object[][] {
},
new String[] {
"ID", "Bairro", "Cidade", "UF"
}
) {
@SuppressWarnings("rawtypes")
Class[] columnTypes = new Class[] {
Integer.class, String.class, String.class, String.class
};
@SuppressWarnings({ "unchecked", "rawtypes" })
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
boolean[] columnEditables = new boolean[] {
false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
};
private JCheckBox chckbxInstantaneo = new JCheckBox("Instantaneo");
/**
* Create the frame.
*/
public ConsBairro() {
try {
prep = Conexao.connect.prepareStatement("CALL sel_bairro(?)");
} catch (SQLException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
setFrameIcon(new ImageIcon(ConsBairro.class.getResource("/br/com/empresa/imagens/bairro.png")));
addInternalFrameListener(new InternalFrameAdapter() {
@Override
public void internalFrameOpened(InternalFrameEvent arg0) {
txtBairro.requestFocus();
}
@Override
public void internalFrameClosed(InternalFrameEvent arg0) {
new Thread(new Runnable() {
public void run() {
try {
prep.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
});
txtBairro.setToolTipText("Nome do Bairro");
txtBairro.setBounds(49, 1, 169, 28);
txtBairro.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent arg0) {
if (chckbxInstantaneo.isSelected()) {
atualizaTabela();
}
}
});
txtBairro.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!chckbxInstantaneo.isSelected()) {
atualizaTabela();
}
}
});
txtBairro.setColumns(10);
setTitle("Consulta Bairros");
setIconifiable(true);
setClosable(true);
setResizable(false);
setBounds(10, 30, 606, 536);
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
lblBairro.setBounds(11, 7, 33, 16);
panel.add(lblBairro);
panel.add(txtBairro);
btnAtualizarBusca.setToolTipText("Atualizar Resultados");
btnAtualizarBusca.setBounds(223, 0, 46, 31);
btnAtualizarBusca.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
atualizaTabela();
}
});
btnAtualizarBusca.setIcon(new ImageIcon(ConsBairro.class.getResource("/br/com/empresa/imagens/tiny_refresh.png")));
panel.add(btnAtualizarBusca);
chckbxInstantaneo.setToolTipText("Busca Instant\u00E2nea");
chckbxInstantaneo.setBounds(274, 6, 163, 18);
panel.add(chckbxInstantaneo);
spTbBairro.setBounds(0, 36, 543, 463);
panel.add(spTbBairro);
tbBairro.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
if (me.getClickCount()==2) {
editarBairro();
}
}
});
tbBairro.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tbBairro.setModel(modelo);
tbBairro.getColumnModel().getColumn(0).setPreferredWidth(50);
tbBairro.getColumnModel().getColumn(1).setPreferredWidth(124);
tbBairro.getColumnModel().getColumn(1).setMinWidth(30);
tbBairro.getColumnModel().getColumn(2).setPreferredWidth(131);
tbBairro.getColumnModel().getColumn(2).setMinWidth(30);
tbBairro.getColumnModel().getColumn(3).setPreferredWidth(31);
tbBairro.getColumnModel().getColumn(3).setMinWidth(10);
spTbBairro.setViewportView(tbBairro);
btnAdicionar.setBounds(545, 36, 46, 30);
btnAdicionar.setToolTipText("Adicionar Novo Bairro");
btnAdicionar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ManBairro b = new ManBairro(0);
//pega o componente "mãe" do internalFrame pra abrir outro internalFrame no componente principal.
getParent().add(b);
b.setVisible(true);
}
});
btnAdicionar.setIcon(new ImageIcon(ConsBairro.class.getResource("/br/com/empresa/imagens/record_add.png")));
panel.add(btnAdicionar);
btnExcluir.setBounds(545, 71, 46, 30);
btnExcluir.setToolTipText("Remover Bairro");
btnExcluir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
excluiBairro();
}
});
btnExcluir.setIcon(new ImageIcon(ConsBairro.class.getResource("/br/com/empresa/imagens/record_discard.png")));
panel.add(btnExcluir);
btnEditar.setBounds(545, 106, 46, 30);
btnEditar.setToolTipText("Editar Bairro");
btnEditar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editarBairro();
}
});
btnEditar.setIcon(new ImageIcon(ConsBairro.class.getResource("/br/com/empresa/imagens/record_edit.png")));
panel.add(btnEditar);
inicializado=true;
}
public void atualizaTabela(){
txtBairro.setEditable(false);
btnAtualizarBusca.setEnabled(false);
new Thread(new Runnable() {
@Override
public void run() {
carregaDados();
txtBairro.setEditable(true);
btnAtualizarBusca.setEnabled(true);
}
}).start();
}
@SuppressWarnings({ "unchecked", "rawtypes" })// Vector
private void carregaDados(){
ResultSet rs = null;
modelo.setNumRows(0);
try {
//String sql = "CALL sel_bairro(?)";
//prep = Conexao.connect.prepareStatement(sql);
prep.setString(1, txtBairro.getText());
rs = prep.executeQuery();
//Guardar os Dados Temporariamente Num 'Vetor' e Mostrar na Tabela
while (rs.next()) {
Vector v = new Vector();
v.addElement(rs.getInt(1)); //ID
v.addElement(rs.getString(2)); //Bairro
v.addElement(rs.getString(3)); //Cidade
v.addElement(rs.getString(4)); //UF
modelo.addRow(v);
}
} catch (SQLException e) {
MostraMsg.msgErro(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
MostraMsg.msgErro(e.getMessage());
e.printStackTrace();
}
}
public void excluiBairro(){
//caso alguma linha esteja selecionada na tabela.
if (tbBairro.getSelectedRow() != -1) {
int id = Integer.parseInt(modelo.getValueAt(tbBairro.getSelectedRow(), 0).toString());
//confirmar a operação
if (JOptionPane.showConfirmDialog(null, "Confirmar Exclusão? \n"+Bairro.infoBairro(id), "Confirmação", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
if (Bairro.excluir(id)){//Retornando true, remove o registro da tabela.
modelo.removeRow(tbBairro.getSelectedRow());
}
}
//Nenhuma Linha selecionado na tabela. Mostrar msg de erro
} else {
MostraMsg.msgErro("É Necessário Selecionar um Bairro na Tabela.");
}
}
public void editarBairro(){
if (tbBairro.getSelectedRow() != -1) {
int id = Integer.parseInt(modelo.getValueAt(tbBairro.getSelectedRow(), 0).toString());
ManBairro mb = new ManBairro(id);
getParent().add(mb);
mb.setVisible(true);
} else {
MostraMsg.msgErro("É Necessário Selecionar um Bairro na Tabela.");
}
}
}
