本文整理汇总了Java中javax.swing.table.DefaultTableModel类的典型用法代码示例。如果您正苦于以下问题:Java DefaultTableModel类的具体用法?Java DefaultTableModel怎么用?Java DefaultTableModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultTableModel类属于javax.swing.table包,在下文中一共展示了DefaultTableModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Soru3
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public Soru3() {
initComponents();
dtm = new DefaultTableModel();
dtm.setColumnIdentifiers(new Object[]{"ID", "ADI", "SOYADI", "MAAS"});
jTable1.setModel(dtm);
try {
// bağlantı için
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/PERSONELDB", "sa", "as");
// iletişimi acıyor
Statement stmt = con.createStatement();
// veritabanında sorgu çalıştırıp bize geri tablo döndürüyor.
ResultSet rs = stmt.executeQuery("SELECT * FROM PERSONEL");
while (rs.next()) {
int id = rs.getInt("ID");
String adi = rs.getString("ADI");
String soyadi = rs.getString("SOYADI");
int maas = rs.getInt("MAAS");
dtm.addRow(new Object[]{id, adi, soyadi, maas});
}
} catch (SQLException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例2: loadTableBD
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public void loadTableBD(int num) {
Result res = db.execute("MATCH (n:`Avion`{numero:"+num+"}) RETURN n.numero, n.type, n.capacite");
DefaultTableModel dtm = new DefaultTableModel(0,0);
String header[] = {"Numero", "Type", "Capacite"};
String test[] = {"n.numero", "n.type", "n.capacite"};
dtm.setColumnIdentifiers(header);
jTable1.setModel(dtm);
while(res.hasNext()) {
Map<String, Object> row = res.next();
Map<String, Object> obj = new LinkedHashMap();
for (String t:test) {
obj.put(t, null);
}
for(Map.Entry<String, Object> col : row.entrySet()) {
obj.put(col.getKey(),col.getValue());
}
dtm.addRow(obj.values().toArray());
}
}
示例3: populatetable
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
/**
* Loads the Data Array into the tmodel
*
* @param table to be populated
* @param header column header
* @param rows nullRoww data
* @return populated tmodel
*/
public static JTable populatetable(JTable table, String[] header, List<String[]> rows) {
removeRowSelection(table);
DefaultTableModel tablemodel = (DefaultTableModel) table.getModel();
tablemodel.setRowCount(0);
for (String col : header) {
tablemodel.addColumn(col);
}
for (String[] row : rows) {
tablemodel.addRow(row);
}
table.setModel(tablemodel);
return table;
}
示例4: ControlerHistorico
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public ControlerHistorico(Historico historico) {
this.historico = historico;
this.historico.getTbl_Historico().getColumnModel().getColumn(2).setPreferredWidth(170);
this.historico.getTbl_Historico().getColumnModel().getColumn(4).setPreferredWidth(485);
dtm = (DefaultTableModel) this.historico.getTbl_Historico().getModel();
this.historico.getBtn_Cancelar().addActionListener(this);
this.historico.getBtn_Ok().addActionListener(this);
this.historico.getRbt_Data().addActionListener(this);
this.historico.getRbt_Todas().addActionListener(this);
getDados();
preencheTabela();
this.historico.setVisible(true);
}
示例5: QueryResultViewer
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public QueryResultViewer() {
resultSet = null;
tableModel = new DefaultTableModel();
emptyResultLabel = new JLabel(EMPTY_RESULT_MSG);
mainContainer = new JPanel();
setLayout(new BorderLayout());
tableSP = new JScrollPane(graphicTable,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableSP.setBorder(BorderFactory.createEmptyBorder());
graphicTable.setModel(tableModel);
graphicTable.setFillsViewportHeight(true);
graphicTable.setEnabled(false);
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
resizeColumnWidth(COL_MIN_WIDTH);
}
});
mainContainer.add(tableSP);
setLayout(new GridLayout(1,1));
add(tableSP);
}
示例6: populatePostPayTable
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
private void populatePostPayTable(DefaultTableModel model) {
// import all customers from database
final PostingDaoImpl postingDaoImpl = new PostingDaoImpl();
List<Posting> postingList = postingDaoImpl.getAllPostingsByRoomNumber(roomNumber, hotelSystemStatus.getDateTime().toString());
final PaymentDaoImpl paymentDaoImpl = new PaymentDaoImpl();
List<Payment> paymentlist = paymentDaoImpl.getAllPaymentsByRoomNumber(roomNumber, hotelSystemStatus.getDateTime().toString());
// clean table model
model.setRowCount(0);
for (Posting pos : postingList) {
model.addRow(new Object[] { pos.getId(), pos.getPostType(), pos.getTitle(), pos.getPrice(),
pos.getCurrency(), pos.getExplanation(), pos.getDateTime() });
}
for (Payment pay : paymentlist) {
model.addRow(new Object[] { pay.getId(), pay.getPaymentType(), pay.getTitle(), pay.getPrice(),
pay.getCurrency(), pay.getExplanation(), pay.getDateTime() });
}
}
示例7: addAction
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
private void addAction() {
VariableEditDialog dialog = new VariableEditDialog();
dialog.setTitle("Create New Variable");
dialog.getButtonOK().addActionListener(it -> {
String key = dialog.getKeyTextField().getText().trim();
String value = dialog.getValueTextField().getText().trim();
DefaultTableModel tableModel = (DefaultTableModel) varTable.getModel();
String[] rowValues = {key, value};
tableModel.addRow(rowValues);
dialog.setVisible(false);
});
dialog.setSize(300, 150);
dialog.setAlwaysOnTop(true);
dialog.setLocationRelativeTo(rootPanel);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
示例8: preencheTabela
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
@Override
public void preencheTabela() {
dtm = (DefaultTableModel) this.cadastroLanche.getjTable1().getModel();
if (this.lanches != null) {
for (Lanche lan : lanches) {
dtm.insertRow(dtm.getRowCount(), new Object[]{
lan.getNome(),
lan.getPreco()
});
}
}
this.cadastroLanche.getLista_ingredientes().setModel(dlmIng);
this.cadastroLanche.getLista_lanche().setModel(dlmLan);
for (int i = 0; i < this.ingredientes.size(); i++) {
dlmIng.add(i, this.ingredientes.get(i).getNome());
}
}
示例9: construtorPanelIndicador
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
private void construtorPanelIndicador(){
Object[] colunas = new String[]{"Pesquisa","Resultado"};
Object[][] dados = new Object[][]{
};
model = new DefaultTableModel(dados , colunas ){
public boolean isCellEditable(int row, int col){
return false;
}
};
tabela = new JTable();
tabela.setModel(model);
tabela.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
painelTabela = new JScrollPane();
painelTabela.setViewportView(tabela);
// busca e inserção dos resultados na tabela
this.consultaIndicadores();
}
示例10: loadTableBD
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public void loadTableBD(String dateAuj) {
Result res = db.execute("MATCH (a:Avion)-[r:Affecter]->(d:Depart)<-[c:Constituer]-(v:Vol) WHERE d.date='"+dateAuj+"' RETURN d.numero, d.date, v.villeDep, v.villeArr, a.type, a.capacite, v.numero, v.heureDep, v.heureArr");
DefaultTableModel dtm = new DefaultTableModel(0,0);
String header[] = {"Numero", "Date","Depart", "Arriveé", "Type", "Capacite", "NumVol", "Heure De Depart", "Heure d'arrive"};
String test[] = {"d.numero", "d.date","v.villeDep", "v.villeArr", "a.type", "a.capacite", "v.numero", "v.heureDep", "v.heureArr"};
dtm.setColumnIdentifiers(header);
jTable1.setModel(dtm);
while(res.hasNext()) {
Map<String, Object> row = res.next();
Map<String, Object> obj = new LinkedHashMap();
for (String t:test) {
obj.put(t, null);
}
for(Map.Entry<String, Object> col : row.entrySet()) {
obj.put(col.getKey(),col.getValue());
}
dtm.addRow(obj.values().toArray());
}
}
示例11: addContentLine
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public void addContentLine(ServerLogMessage deseriaLogMessage) {
try {
DefaultTableModel model = (DefaultTableModel) this.table.getModel();
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
model.addRow(new String[]{timeStamp, deseriaLogMessage.getSource().getValue(),
deseriaLogMessage.getLogLevel().toString(), deseriaLogMessage.getContent()});
} catch (ArrayIndexOutOfBoundsException e) {
//Tries again n times, error was caused by 2 threads accessing the table at the same time
int n = 10;
int i=0;
while (!retryAddContentLine(deseriaLogMessage) && i<n) {
i++;
}
if (i==n) {
//retrying failed
throw e;
}
}
}
示例12: loadUsersTable
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
private void loadUsersTable() {
ArrayList<User> usersList = UserController.getUsersList();
if (usersList.size() > 0) {
DefaultTableModel def = (DefaultTableModel) users_table.getModel();
def.setNumRows(0);
for (User user : usersList) {
String userName = user.getUserName();
String userDisplayName = user.getUserDisplayName();
UserLevel userLevel = user.getUserLevel();
Integer userType = user.getUserType();
Integer userStatus = user.getUserStatus();
Vector v = new Vector();
v.add(user);
v.add(userDisplayName);
v.add(userLevel.getLevelDisplayName());
v.add(userType == 1 ? "Permanent" : "Temporary");
v.add((userStatus == 1));
def.addRow(v);
}
}
}
示例13: loadTableBD
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public void loadTableBD() {
Result res = db.execute("MATCH (n:`Vol`) RETURN n.numero, n.villeDep, n.villeArr, n.heureDep, n.heureArr, n.distance, n.frequence ORDER BY n.numero");
DefaultTableModel dtm = new DefaultTableModel(0,0);
String header[] = {"n.numero", "Depart", "Arrivee", "Heure Depart", "Heure Arrivee", "Distance", "Frequence"};
String test[] = {"n.numero", "n.villeDep", "n.villeArr", "n.heureDep", "n.heureArr", "n.distance", "n.frequence"};
dtm.setColumnIdentifiers(header);
jTable1.setModel(dtm);
while(res.hasNext()) {
Map<String, Object> row = res.next();
Map<String, Object> obj = new LinkedHashMap();
for (String t:test) {
obj.put(t, null);
}
for(Entry<String, Object> col : row.entrySet()) {
obj.put(col.getKey(),col.getValue());
}
dtm.addRow(obj.values().toArray());
}
}
示例14: ControlerPedidos
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
public ControlerPedidos(Pedidos pedidos) {
this.pedidos = pedidos;
this.pedidos.getTbl_Pedidos().getColumnModel().getColumn(0).setPreferredWidth(240);
this.pedidos.getTbl_Pedidos().getColumnModel().getColumn(1).setPreferredWidth(585);
this.pedidos.getBtn_Anterior().addActionListener(this);
this.pedidos.getBtn_Cancelar().addActionListener(this);
this.pedidos.getBtn_Entregue().addActionListener(this);
this.pedidos.getBtn_Primeiro().addActionListener(this);
this.pedidos.getBtn_Proximo().addActionListener(this);
this.pedidos.getBtn_Ultimo().addActionListener(this);
this.pedidos.getMnu_atualizar_pedidos().addActionListener(this);
getDados();
this.dtm = (DefaultTableModel) this.pedidos.getTbl_Pedidos().getModel();
preencheTabela();
this.pedidos.setVisible(true);
}
示例15: pasteFromClipboard
import javax.swing.table.DefaultTableModel; //导入依赖的package包/类
/**
* Reads clipboard data and converts it into supported format and fills the
* tmodel cells
*
* @param table the target tmodel
*/
private static void pasteFromClipboard(JTable table) {
int startRow = table.getSelectedRows()[0];
int startCol = table.getSelectedColumns()[0];
String pasteString;
try {
pasteString = (String) (CLIPBOARD.getContents(CLIPBOARD).getTransferData(DataFlavor.stringFlavor));
} catch (UnsupportedFlavorException | IOException ex) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
return;
}
String[] lines = pasteString.split(LINE_BREAK);
for (int i = 0; i < lines.length; i++) {
String[] cells = lines[i].split(CELL_BREAK);
if (table.getRowCount() <= startRow + i) {
((DefaultTableModel) table.getModel()).addRow(nullRow);
}
for (int j = 0; j < cells.length; j++) {
if (table.getColumnCount() > startCol + j) {
if (table.isCellEditable(startRow + i, startCol + j)) {
table.setValueAt(cells[j], startRow + i, startCol + j);
}
}
}
}
}