0
I couldn’t display the title of the chart, could you help?
Obs.: I inserted it "JScrollPane scroll = new JScrollPane(tabela);
" and "contentPane.add(scroll);
" or "getContentPane.add(scroll)
" as I saw in questions/answers of this site, but I was not successful.
Code:
package tabelas;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Tabelas {
public static void main(String[] args) {
// TODO code application logic here
JFrame j = new JFrame("Bora mecao");
j.setBounds(0,0,400,400);
JTable tabela = new JTable();
tabela.setBounds(10,10,200,200);
j.add(tabela);
String[] colunas = {"Marca", "Local"};
DefaultTableModel modelo = (new DefaultTableModel(){
@Override
public boolean isCellEditable(int row, int column){
return false;
}
});
modelo.setColumnIdentifiers(colunas);
modelo.setRowCount(0);
Object[] objetos = new Object[2];
objetos[0] = "LG";
objetos[1] = "Chalé";
modelo.addRow(objetos);
tabela.setModel(modelo);
JScrollPane scroll = new JScrollPane(tabela);
contentPane.add(scroll);
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setLayout(null);
j.setVisible(true);
}
}
Thanks for all your help!
– LUIZ