Jtable

1 resposta
A

Olá pessoal,

Venho do delphi onde é muito facil mostrar os dados numa grid, estou tentando fazer isso no java, usando o jbuilder mais não estou conseguindo.
sera q alguem tem um exemplo, ou pode me ajudar a fazer uma grid no jbulder.

JTable tt new JTable();
mais não aparece nada na tela, também não da erro nem um.

obrigado

1 Resposta

D

Vc tem que criar um TableModel.....só isso ae não funciona não

tá ai um exemplo

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

public class ExampleTableModel extends AbstractTableModel {
  String columnName[] = { "description", "data", "boolean values" };

  Class columnType[] = { String.class, String.class, Boolean.class };

  Object table[][] = { { "this is line", "data", new Boolean(true) },
      { "this is line", "data", new Boolean(false) },
      { "this is line", "data", new Boolean(true) },
      { "this is line", "data", new Boolean(false) },
      { "this is line", "data", new Boolean(true) },
      { "this is line", "data", new Boolean(false) },
      { "this is line", "data", new Boolean(true) },
      { "this is line", "data", new Boolean(false) },
      { "this is line", "data", new Boolean(true) } };

  public int getColumnCount() {
    return table[0].length;
  }

  public int getRowCount() {
    return table.length;
  }

  public Object getValueAt(int r, int c) {
    return table[r][c];
  }

  public String getColumnName(int column) {
    return columnName[column];
  }

  public Class getColumnClass(int c) {
    return columnType[c];
  }

  public boolean isCellEditable(int r, int c) {
    return false;
  }

  public void setValueAt(Object aValue, int r, int c) {
  }
  public static void main(String[] arg){
    JFrame f = new JFrame();
    f.getContentPane().add(new JScrollPane(new JTable(new ExampleTableModel())));
    f.setSize(300,300);
    f.show();
  }
}

Um abraço !

Criado 25 de abril de 2006
Ultima resposta 25 de abr. de 2006
Respostas 1
Participantes 2