當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTableModel類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:sametkaya,項目名稱:Java_Swing_Programming,代碼行數:27,代碼來源:Soru3.java

示例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());
}
}
 
開發者ID:ATF19,項目名稱:flight-management-system-java,代碼行數:21,代碼來源:AfficherAvions.java

示例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;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:22,代碼來源:JtableUtils.java

示例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);
}
 
開發者ID:wesleyreis1808,項目名稱:projetomcdonalds,代碼行數:18,代碼來源:ControlerHistorico.java

示例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);
}
 
開發者ID:tteguayco,項目名稱:JITRAX,代碼行數:27,代碼來源:QueryResultViewer.java

示例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() });
		}
	}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:25,代碼來源:RoomWindow.java

示例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);
}
 
開發者ID:hykes,項目名稱:CodeGen,代碼行數:21,代碼來源:VariableUI.java

示例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());
    }

}
 
開發者ID:wesleyreis1808,項目名稱:projetomcdonalds,代碼行數:21,代碼來源:ControlerCadastroLanche.java

示例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();
		
	}
 
開發者ID:matheusPeresDeAraujo,項目名稱:20170612-NotaFIscalEletronica,代碼行數:23,代碼來源:FrameIndicadores.java

示例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());
}
}
 
開發者ID:ATF19,項目名稱:flight-management-system-java,代碼行數:21,代碼來源:MainWindow.java

示例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;
        }

         }
}
 
開發者ID:Echtzeitsysteme,項目名稱:mindroid,代碼行數:22,代碼來源:MindroidServerFrame.java

示例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);
        }
    }
}
 
開發者ID:isu3ru,項目名稱:java-swing-template,代碼行數:24,代碼來源:Preferences.java

示例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());
}
}
 
開發者ID:ATF19,項目名稱:flight-management-system-java,代碼行數:21,代碼來源:AfficherVols.java

示例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);

}
 
開發者ID:wesleyreis1808,項目名稱:projetomcdonalds,代碼行數:22,代碼來源:ControlerPedidos.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:32,代碼來源:JtableUtils.java


注:本文中的javax.swing.table.DefaultTableModel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。