[quote=silviogs]Olá amigo
Onde está a parte de inicialização da tabbedpane “do minha tabbed pane fica só com a borda de cima”
está faltando algum código deste programa?
tem muitos exemplos aqui:
http://www.java2s.com/Code/Java/Swing-JFC/TabbedPane.htm
Dê uma olhada, acho que pode lhe ajudar.
Silvio Guedes[/quote]
Opa, desculpa amigo, me esqueci, segue aqui o mesmo
public class TelaAdd extends JFrame implements ActionListener
{
BancoDeDados bd = new BancoDeDados();
LeitorTXT letxt = new LeitorTXT();
JButton btsal = new JButton("Salvar");
JButton btlim = new JButton("Limpar");
JButton btcan = new JButton("Cancelar");
JButton btadd = new JButton("Adicionar");
JButton btlimad = new JButton("Limpar");
JButton btproend = new JButton("O");
JButton btprocep = new JButton("O");
JButton btaddmat = new JButton("+");
JButton btremmat = new JButton("-");
JTextField txtnome = new JTextField();
JTextField txtcomp = new JTextField();
JTextField txtrua = new JTextField();
JTextField txtbairro = new JTextField();
JRadioButton rbcpf = new JRadioButton("CPF");
JRadioButton rbcnpj = new JRadioButton("CNPJ");
JLabel lblcnpj = new JLabel("CPF:");
MaskFormatter mcpf = Formatar("###.###.###-##");
JFormattedTextField txtcep = new JFormattedTextField(Formatar("#####-###"));
JFormattedTextField txtcepreg = new JFormattedTextField(Formatar("#####-###"));
JFormattedTextField txttelres = new JFormattedTextField(Formatar("(##) ####-####"));
JFormattedTextField txttelcel = new JFormattedTextField(Formatar("(##) #####-####"));
JFormattedTextField txtregistro = new JFormattedTextField(mcpf);
DefaultTableModel modelo = new DefaultTableModel(new String [] {"Tipo produto", "Produto", "Quantidade"}, 0);
JTable tabela = new JTable(modelo);
JDateChooser centrega = new JDateChooser();
JDateChooser cretirada = new JDateChooser();
JTextField txtend = new JTextField();
JTextField txtnum = new JTextField();
JTextField txtcom = new JTextField();
JTextField txtbai = new JTextField();
public TelaAdd()
{
super("Locare | Adicionar Pedidos");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLayout(null);
setResizable(false);
setSize(850, 550);
setLocationRelativeTo(null);
setVisible(true);
DefaultTableCellRenderer numeros = new DefaultTableCellRenderer();
numeros.setHorizontalAlignment(SwingConstants.CENTER);
JScrollPane spmat = new JScrollPane(tabela);
spmat.setBorder(BorderFactory.createEtchedBorder());
JTabbedPane tpdados = new JTabbedPane();
((DefaultTableCellRenderer) tabela.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
tabela.getColumnModel().getColumn(2).setCellRenderer(numeros);
tabela.getTableHeader().setReorderingAllowed(false);
JPanel pdados = new JPanel();
JPanel pdadosreg = new JPanel();
//pdados
JLabel lbltitulo = new JLabel("Novo Pedido");
JLabel lblnome = new JLabel("Nome completo:");
JLabel lbltelres = new JLabel("Telefone Residencial:");
JLabel lbltelcel = new JLabel("Telefone Celular:");
JLabel lblcomp = new JLabel("Complemento:");
JLabel lblend = new JLabel("Endereço:");
JLabel lblbairro = new JLabel("Bairro:");
JLabel lblcep = new JLabel("CEP:");
//pdadoreg
JLabel lblendreg = new JLabel("Endereço:");
JLabel lblnum = new JLabel("Nº:");
JLabel lblcom = new JLabel("Complemento:");
JLabel lblbai = new JLabel("Bairro:");
JLabel lblhorfes = new JLabel("Hora da Festa:");
JLabel lbldatent = new JLabel("Data da entrega:");
JLabel lbldatret = new JLabel("Data da retirada:");
ButtonGroup group = new ButtonGroup();
lbltitulo.setFont(new Font("Anjelika Rose", Font.BOLD, 25));
txtregistro.setEnabled(false);
pdados.setLayout(null);
pdadosreg.setLayout(null);
spmat.setBounds(12, 224, 342, 267);
rbcpf.setBounds(514, 92, 48, 20);
rbcnpj.setBounds(568, 92, 60, 20);
centrega.setBounds(407, 57, 140, 26);
cretirada.setBounds(664, 57, 140, 26);
//pdados
lblnome.setBounds(27, 12, 110, 16);
lbltelres.setBounds(30, 94, 128, 16);
lbltelcel.setBounds(284, 94, 105, 16);
lblend.setBounds(27, 54, 35, 16);
lblcomp.setBounds(254, 53, 92, 16);
lblbairro.setBounds(434, 54, 47, 16);
lblcep.setBounds(658, 53, 35, 16);
lblcnpj.setBounds(640, 94, 68, 16);
//pdadosreg
lblendreg.setBounds(16, 26, 66, 16);
lblnum.setBounds(420, 26, 27, 16);
lblcom.setBounds(496, 26, 92, 16);
lblbai.setBounds(16, 63, 47, 16);
lbldatent.setBounds(306, 63, 110, 13);
lbldatret.setBounds(559, 63, 110, 13);
lblhorfes.setBounds(227, 172, 88, 13);
lblcep.setBounds(658, 12, 35, 16);
//pdados
txtnome.setBounds(130, 9, 502, 23);
txtrua.setBounds(67, 50, 180, 23);
txtcomp.setBounds(347, 49, 72, 23);
txtbairro.setBounds(487, 50, 153, 23);
txtcep.setBounds(695, 12, 100, 23);
txttelres.setBounds(164, 89, 100, 27);
txttelcel.setBounds(385, 89, 110, 27);
txtregistro.setBounds(675, 89, 110, 27);
//pdadosreg
txtend.setBounds(87, 23, 329, 23);
txtnum.setBounds(444, 23, 37, 23);
txtcom.setBounds(585, 23, 72, 23);
txtcepreg.setBounds(280, 26, 100, 23);
txtbai.setBounds(63, 60, 236, 23);
btsal.setBounds(420, 380, 120, 54);
btlim.setBounds(542, 380, 120, 54);
btcan.setBounds(664, 380, 116, 54);
btaddmat.setBounds(356, 244, 40, 40);
btremmat.setBounds(356, 283, 40, 40);
btsal.setToolTipText("Pressiona ALT + S para adicionar");
btlim.setToolTipText("Pressiona ALT + L para limpar");
btcan.setToolTipText("Pressiona ALT + C para cancelar");
btsal.addActionListener(this);
btlim.addActionListener(this);
btcan.addActionListener(this);
btaddmat.addActionListener(this);
btremmat.addActionListener(this);
rbcnpj.addActionListener(this);
rbcpf.addActionListener(this);
btsal.setMnemonic('a');
btlim.setMnemonic(KeyEvent.VK_L);
btcan.setMnemonic(KeyEvent.VK_C);
pdados.add(lblnome);
pdados.add(lbltelres);
pdados.add(lbltelcel);
pdados.add(lblcomp);
pdados.add(lblbairro);
pdados.add(lblcep);
pdados.add(lbltelres);
pdados.add(lbltelcel);
pdados.add(lblcnpj);
pdados.add(lblend);
pdados.add(txtnome);
pdados.add(txtrua);
pdados.add(txtcomp);
pdados.add(txtbairro);
pdados.add(txtcep);
pdados.add(txttelres);
pdados.add(txttelcel);
pdados.add(txtregistro);
pdadosreg.add(txtend);
pdadosreg.add(txtnum);
pdadosreg.add(txtcom);
pdadosreg.add(txtbai);
pdadosreg.add(lblendreg);
pdadosreg.add(lblnum);
pdadosreg.add(lblcom);
pdadosreg.add(lblbai);
pdadosreg.add(lbldatent);
pdadosreg.add(lbldatret);
pdadosreg.add(centrega);
pdadosreg.add(cretirada);
pdados.add(rbcpf);
pdados.add(rbcnpj);
tpdados.addTab("Dados do cliente", pdados);
tpdados.addTab("Dados do pedido", pdadosreg);
group.add(rbcpf);
group.add(rbcnpj);
pdados.setBounds(0, 0, 816, 157);
tpdados.setBounds(9, 46, 816, 157);
lbltitulo.setBounds(23, 6, 190, 33);
getContentPane().add(lbltitulo);
getContentPane().add(tpdados);
getContentPane().add(spmat);
getContentPane().add(btsal);
getContentPane().add(btlim);
getContentPane().add(btcan);
getContentPane().add(btaddmat);
getContentPane().add(btremmat);
}
public MaskFormatter Formatar(String mascara)
{
try
{
MaskFormatter mascara1 = new MaskFormatter(mascara);
return mascara1;
}
catch(Exception e)
{
return null;
}
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btcan)
{
this.dispose();
}
else if(e.getSource() == btlim)
{
txtnome.setText("");
txtrua.setText("");
txtcomp.setText("");
txtbairro.setText("");
txtcep.setText("");
txttelres.setText("");
txttelcel.setText("");
int tot = modelo.getRowCount();
for(int i = tot; tot > 0; tot--)
{
modelo.removeRow(modelo.getRowCount() - 1);
}
}
else if(e.getSource() == btaddmat)
{
try
{
ArrayList<String> teste = bd.procuraTipos();
String[] lmaterial = new String[teste.size()];
String[] ltipomat = new String[teste.size()];
for(int i = 0; i < teste.size(); i++)
{
lmaterial[i] = teste.get(i);
}
TableColumn material = tabela.getColumnModel().getColumn(0);
TableColumn col = tabela.getColumnModel().getColumn(1);
material.setCellEditor(new MyComboBoxEditor(lmaterial));
material.setCellRenderer(new ComboBoxRenderer(lmaterial));
col.setCellEditor(new MyComboBoxEditor(ltipomat));
col.setCellRenderer(new ComboBoxRenderer(ltipomat));
tabela.setRowHeight(25);
modelo.addRow(new Object[] {"", ""});
}
catch(Exception e1)
{
}
}
else if(e.getSource() == btremmat)
{
int coluna = tabela.getSelectedRow();
if(coluna >= 0)
{
modelo.removeRow(coluna);
}
}
else if(e.getSource() == btsal)
{
System.out.println(txtcep.getText());
try
{
String texto = "Dados inseridos:\nNome: " + txtnome.getText() + "\nRua: " + txtrua.getText();
texto = texto + "\nBairro: " + txtbairro.getText() + "\nComplemento: " + txtcomp.getText();
texto = texto + "\nTel Res: " + txttelres.getText() + "\nTel Cel: " + txttelcel.getText();
JOptionPane.showConfirmDialog(null, texto);
Pedido pd = new Pedido();
pd.setNome(txtnome.getText());
pd.setEndereco(txtrua.getText());
pd.setBairro(txtbairro.getText());
pd.setComplemento(txtcomp.getText());
pd.setTelres(letxt.desformata(txttelres.getText()));
pd.setTelcel(Integer.parseInt(txttelcel.getText()));
pd.setCep(Integer.parseInt(txtcep.getText()));
}
catch(Exception erro)
{
JOptionPane.showMessageDialog(null,"Impossível proceder com campos vazios");
erro.printStackTrace();
}
this.dispose();
}
else if(e.getSource() == rbcpf)
{
lblcnpj.setText("CPF:");
txtregistro.setEnabled(true);
try
{
mcpf.setMask("###.###.###-##");
}
catch (ParseException e1)
{
}
}
else if(e.getSource() == rbcnpj)
{
lblcnpj.setText("CNPJ:");
txtregistro.setEnabled(true);
try
{
mcpf.setMask("##.###.###/####-##");
}
catch (ParseException e1)
{
}
}
}
class ComboBoxRenderer extends JComboBox<String> implements TableCellRenderer
{
public ComboBoxRenderer(String[] items)
{
super(items);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected)
{
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
}
else
{
setForeground(table.getForeground());
setBackground(table.getBackground());
}
setSelectedItem(value);
return this;
}
}
class MyComboBoxEditor extends DefaultCellEditor
{
public MyComboBoxEditor(String[] items)
{
super(new JComboBox<String>(items));
}
}
}