Java Code Examples for javax.swing.table.DefaultTableModel#addRow()

The following examples show how to use javax.swing.table.DefaultTableModel#addRow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickNoteForm.java    From MooTool with MIT License 7 votes vote down vote up
public static void initNoteListTable() {
    String[] headerNames = {"id", "名称"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    quickNoteForm.getNoteListTable().setModel(model);
    // 隐藏表头
    JTableUtil.hideTableHeader(quickNoteForm.getNoteListTable());
    // 隐藏id列
    JTableUtil.hideColumn(quickNoteForm.getNoteListTable(), 0);

    Object[] data;

    List<TQuickNote> quickNoteList = quickNoteMapper.selectAll();
    for (TQuickNote tQuickNote : quickNoteList) {
        data = new Object[2];
        data[0] = tQuickNote.getId();
        data[1] = tQuickNote.getName();
        model.addRow(data);
    }
    if (quickNoteList.size() > 0) {
        quickNoteForm.getTextArea().setText(quickNoteList.get(0).getContent());
        quickNoteForm.getNoteListTable().setRowSelectionInterval(0, 0);
        QuickNoteListener.selectedName = quickNoteList.get(0).getName();
    }
}
 
Example 2
Source File: Main_CustomersFrame.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 6 votes vote down vote up
private void populateMainTable(DefaultTableModel model) {

        model.setRowCount(0);
        
        customerDaoImpl = new CustomerDaoImpl();
        final List<Customer> customerList = customerDaoImpl.getAllCustomers();
        
        if(!customerList.isEmpty()) {
        	final ReservationDaoImpl reservationDaoImpl = new ReservationDaoImpl();

            for (Customer cust : customerList) {

                final Optional<Reservation> reservation = reservationDaoImpl.findReservationById(cust.getReservationId());

                if (!reservation.isPresent()) {
                    continue;
                }

                final Object[] customerObject = new Object[]{reservation.get().getRentedRoomNum(), reservation.get().getId(),
                    cust.getFirstName(), cust.getLastName(), reservation.get().getAgency(), reservation.get().getGroupName(),
                    reservation.get().getCheckinDate(), reservation.get().getCheckoutDate(), cust.getCountry()};
                model.addRow(customerObject);
            }
        }

    }
 
Example 3
Source File: SecurityRolesEditorPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initTable(JTable table, String[] data, String columnName) {
    DefaultTableModel model = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    
    model.addColumn(columnName);
     
    for (int i = 0; i < data.length; i++) {
        model.addRow(new Object[] {data[i]});
    }
    
    table.setModel(model);
}
 
Example 4
Source File: MobileUtil.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public Rect loadValuesToTable() {
    if (tree.getSelectionPath() != null) {
        Object selected = tree.getSelectionPath().getLastPathComponent();
        if (selected instanceof MobileTreeNode) {
            MobileTreeNode treenode = (MobileTreeNode) selected;
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            removeAllRows(model);
            for (Object attr : treenode.getAttributes().keySet()) {
                model.addRow(new Object[]{attr, treenode.getAttributes().get(attr)});
            }
            return treenode.getBounds();
        }
    }
    return null;
}
 
Example 5
Source File: SecurityRolesEditorPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    int[] selectedRows = allRolesTable.getSelectedRows();
    DefaultTableModel allRolesTableModel = (DefaultTableModel) allRolesTable.getModel();
    DefaultTableModel selectedRolesTableModel = (DefaultTableModel) selectedRolesTable.getModel();
    
    // Get the list of selected role names
    for (int i = 0; i < selectedRows.length; i++) {
        String roleName = (String) allRolesTableModel.getValueAt(selectedRows[i], 0);
        selectedRolesTableModel.addRow(new Object[] {roleName});
    }
    
    // Now remove the selected rows from the allRolesTable
    for (int i = selectedRows.length-1; i >=0; i--) {
        allRolesTableModel.removeRow(selectedRows[i]);
    }
}
 
Example 6
Source File: AvdUISelector.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public final void setAvdInfos(AvdInfo[] infos) {
    avdInfos = infos;
    DefaultTableModel tableModel = getTableModel();
    tableModel.setRowCount(0);
    for (AvdInfo info : infos) {
        AndroidVersion target = info.getAndroidVersion();
        if (target != null) {
            tableModel.addRow(new Object[]{
                info.getName(), target.getApiLevel(), target.getCodename(), target.getFeatureLevel()
            });
        } else {
            LOG.log(Level.INFO, "Not valid AvdInfo {0}", info);
        }
    }
    if (infos.length > 0) {
        avdsTable.setRowSelectionInterval(0, 0); // pre-select 1st row
    }
}
 
Example 7
Source File: AddUpdateRowDialog.java    From AndroidDBvieweR with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form AddUpdateRowDialog
 */
public AddUpdateRowDialog(DefaultTableModel mainTableModel, RowController rowController, Object[] columns, Object[] row, int rowIndex) {
    super(new Frame(), true);
    initComponents();
    setLocationRelativeTo(null);
    defaultTableModel = (DefaultTableModel) addUpdateRowTable.getModel();
    this.mainTableModel = mainTableModel;
    this.rowController = rowController;
    this.columns = columns;
    this.row = row;
    this.rowIndex = rowIndex;
    if (row == null) {
        setTitle("Add new row");
        for (Object column : columns) {
            defaultTableModel.addRow(new Object[]{column, ""});
        }
    } else {
        setTitle("Update row");
        for (int i = 0; i < columns.length; i++) {
            defaultTableModel.addRow(new Object[]{columns[i], row[i]});
        }
    }
}
 
Example 8
Source File: SynthesisReportGui.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Present data in javax.swing.table.DefaultTableModel form.
 *
 * @param model   {@link ObjectTableModel}
 * @param formats Array of {@link Format} array can contain null formatters in this case value is added as is
 * @param columns Columns headers
 * @return data in table form
 */
public static DefaultTableModel getAllDataAsTable(ObjectTableModel model, Format[] formats, String[] columns) {
    final List<List<Object>> table = getAllTableData(model, formats);

    final DefaultTableModel tableModel = new DefaultTableModel();

    for (String header : columns) {
        tableModel.addColumn(header);
    }

    for (List<Object> row : table) {
        tableModel.addRow(new Vector(row));
    }

    return tableModel;
}
 
Example 9
Source File: MobileObjectSpy.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void loadDefaultAppiumCaps() {
    DefaultTableModel model = (DefaultTableModel) jTable3.getModel();
    model.setRowCount(0);
    model.addRow(new Object[]{"udid", null});       
    model.addRow(new Object[]{"deviceName", "iPhone 5s"});
    model.addRow(new Object[]{"platformName", "iOS"});
    model.addRow(new Object[]{"platformVersion", "8.2"});
    model.addRow(new Object[]{"automationName", "XCUITest"});
    model.addRow(new Object[]{"bundleId", ""});
    model.addRow(new Object[]{"xcodeOrgId", "<Team ID>"});
    model.addRow(new Object[]{"xcodeSigningId", "iPhone Developer"});
    model.addRow(new Object[]{"noReset", "true"});
    model.addRow(new Object[]{"app", "application.app"});
}
 
Example 10
Source File: Main_Blockade.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
public void populateBlokajCustomerModel(DefaultTableModel blokajCustomerModel, String reservId) {
    if (blokajRoomsModel.getRowCount() == 0) {

        blokajCustomerModel.setRowCount(0);
    } else {
        for (int k = 0; k < customerList.size(); k++) {
            if (customerList.get(k).getReservationId() == Long.parseLong(reservId)) {
                blokajCustomerModel.addRow(new Object[]{
                    customerList.get(k).getFirstName(), customerList.get(k).getLastName()});
            }
        }
    }
}
 
Example 11
Source File: DriverSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void loadDriverPropTable() {
    DefaultTableModel model = (DefaultTableModel) driverPropTable.getModel();
    model.setRowCount(0);
    for (Object key : settings.getDriverSettings().orderedKeys()) {
        Object value = settings.getDriverSettings().get(key);
        model.addRow(new Object[]{key, value});
    }
}
 
Example 12
Source File: SwitchWxAccountDialog.java    From WePush with MIT License 5 votes vote down vote up
/**
 * 多账号表格
 */
public void renderTable() {
    String[] headerNames = {"id", "账号名称", "AppId", "AppSecret", "Token", "AesKey"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    accountsTable.setModel(model);

    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) accountsTable.getTableHeader()
            .getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    List<TWxAccount> wxAccountList = wxAccountMapper.selectByAccountType(SettingListener.wxAccountType);
    Object[] data;
    for (TWxAccount tWxAccount : wxAccountList) {
        data = new Object[6];
        data[0] = tWxAccount.getId();
        data[1] = tWxAccount.getAccountName();
        data[2] = tWxAccount.getAppId();
        data[3] = tWxAccount.getAppSecret();
        data[4] = tWxAccount.getToken();
        data[5] = tWxAccount.getAesKey();
        model.addRow(data);
    }

    // 隐藏id列
    JTableUtil.hideColumn(accountsTable, 0);
}
 
Example 13
Source File: ScrDeclensionGenClassic.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * populates transforms of currently selected rule
 */
private void populateTransforms() {
    DeclensionGenRule curRule = (DeclensionGenRule) lstRules.getSelectedValue();

    transModel = new DefaultTableModel();
    transModel.addColumn("Regex");
    transModel.addColumn("Replacement");
    tblTransforms.setModel(transModel);

    // do not populate if multiple selections
    if (lstRules.getSelectedIndices().length > 1) {
        return;
    }
    
    boolean useConFont = !core.getPropertiesManager().isOverrideRegexFont();

    TableColumn column = tblTransforms.getColumnModel().getColumn(0);
    column.setCellEditor(new PCellEditor(useConFont, core));
    column.setCellRenderer(new PCellRenderer(useConFont, core));
    
    column = tblTransforms.getColumnModel().getColumn(1);
    column.setCellEditor(new PCellEditor(useConFont, core));
    column.setCellRenderer(new PCellRenderer(useConFont, core));

    // do nothing if nothing selected in rule list
    if (curRule == null) {
        return;
    }

    DeclensionGenTransform[] curTransforms = curRule.getTransforms();

    for (DeclensionGenTransform curTrans : curTransforms) {
        Object[] newRow = {curTrans.regex, curTrans.replaceText};
        transModel.addRow(newRow);
    }

    tblTransforms.setModel(transModel);
}
 
Example 14
Source File: Main_Blockade.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
public void populateBlokajRoomsModel(DefaultTableModel blokajRoomsModel, String reservId) {
    if (blokajModel.getRowCount() == 0) {

        blokajRoomsModel.setRowCount(0);
    } else {

        for (int index = 0; index < roomList.size(); index++) {
            if (roomList.get(index).getReservationId() == Long.parseLong(reservId)) {
                blokajRoomsModel.addRow(new Object[]{roomList.get(index).getNumber(), roomList.get(index).getType(),
                    roomList.get(index).getPersonCount()});
                break;
            }
        }
    }
}
 
Example 15
Source File: PropertyEditorPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed
    DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel();
    dtm.addRow(new Object[]{"", ""});
}
 
Example 16
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
private static void addRowData(DefaultTableModel model, RowData data) {
  model.addRow(Collections.nCopies(model.getColumnCount(), data).toArray());
}
 
Example 17
Source File: MessageManageForm.java    From WePush with MIT License 4 votes vote down vote up
/**
 * 初始化消息列表
 */
public static void init() {
    messageManageForm = getInstance();
    // 历史消息管理
    String[] headerNames = {"消息名称"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    messageManageForm.getMsgHistable().setModel(model);
    // 隐藏表头
    JTableUtil.hideTableHeader(messageManageForm.getMsgHistable());

    int msgType = App.config.getMsgType();

    Object[] data;

    if (msgType == MessageTypeEnum.KEFU_CODE) {
        List<TMsgKefu> tMsgKefuList = msgKefuMapper.selectByMsgType(msgType);
        for (TMsgKefu tMsgKefu : tMsgKefuList) {
            data = new Object[1];
            data[0] = tMsgKefu.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.KEFU_PRIORITY_CODE) {
        List<TMsgKefuPriority> tMsgKefuPriorityList = msgKefuPriorityMapper.selectByMsgType(msgType);
        for (TMsgKefuPriority tMsgKefuPriority : tMsgKefuPriorityList) {
            data = new Object[1];
            data[0] = tMsgKefuPriority.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.WX_UNIFORM_MESSAGE_CODE) {
        List<TMsgWxUniform> tMsgWxUniformList = wxUniformMapper.selectByMsgType(msgType);
        for (TMsgWxUniform tMsgWxUniform : tMsgWxUniformList) {
            data = new Object[1];
            data[0] = tMsgWxUniform.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.MA_TEMPLATE_CODE) {
        List<TMsgMaTemplate> tMsgMaTemplateList = msgMaTemplateMapper.selectByMsgType(msgType);
        for (TMsgMaTemplate tMsgMaTemplate : tMsgMaTemplateList) {
            data = new Object[1];
            data[0] = tMsgMaTemplate.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.MA_SUBSCRIBE_CODE) {
        List<TMsgMaSubscribe> tMsgMaSubscribeList = msgMaSubscribeMapper.selectByMsgType(msgType);
        for (TMsgMaSubscribe tMsgMaSubscribe : tMsgMaSubscribeList) {
            data = new Object[1];
            data[0] = tMsgMaSubscribe.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.MP_TEMPLATE_CODE) {
        List<TMsgMpTemplate> tMsgMpTemplateList = msgMpTemplateMapper.selectByMsgType(msgType);
        for (TMsgMpTemplate tMsgMpTemplate : tMsgMpTemplateList) {
            data = new Object[1];
            data[0] = tMsgMpTemplate.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.EMAIL_CODE) {
        List<TMsgMail> tMsgMailList = msgMailMapper.selectByMsgType(msgType);
        for (TMsgMail tMsgMail : tMsgMailList) {
            data = new Object[1];
            data[0] = tMsgMail.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.WX_CP_CODE) {
        List<TMsgWxCp> tMsgWxCpList = msgWxCpMapper.selectByMsgType(msgType);
        for (TMsgWxCp tMsgWxCp : tMsgWxCpList) {
            data = new Object[1];
            data[0] = tMsgWxCp.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.HTTP_CODE) {
        List<TMsgHttp> tMsgHttpList = msgHttpMapper.selectByMsgType(msgType);
        for (TMsgHttp tMsgHttp : tMsgHttpList) {
            data = new Object[1];
            data[0] = tMsgHttp.getMsgName();
            model.addRow(data);
        }
    } else if (msgType == MessageTypeEnum.DING_CODE) {
        List<TMsgDing> tMsgDingList = msgDingMapper.selectByMsgType(msgType);
        for (TMsgDing tMsgDing : tMsgDingList) {
            data = new Object[1];
            data[0] = tMsgDing.getMsgName();
            model.addRow(data);
        }
    } else {
        List<TMsgSms> tMsgSmsList = msgSmsMapper.selectByMsgType(msgType);
        for (TMsgSms tMsgSms : tMsgSmsList) {
            data = new Object[1];
            data[0] = tMsgSms.getMsgName();
            model.addRow(data);
        }
    }
}
 
Example 18
Source File: SearchResultsFrame.java    From Zettelkasten with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method retrieves the result-entry-numbers from a search request "nr" and fills
 * the jTableResult with those entry-numbers and the entries' related titles.
 * 
 * @param searchrequestnr the search request of which we want to display the search results.
 */
private void prepareResultList(int searchrequestnr) {
    // get search results
    int[] result = searchrequest.getSearchResults(searchrequestnr);
    // save current search request number
    searchrequest.setCurrentSearch(searchrequestnr);
    // check whether we have any results
    if (result!=null) {
        // tell selection listener to do nothing...
        tableUpdateActive = true;
        // sort the array with the entry-numbers of the search result
        if (result.length>0) Arrays.sort(result);
        // get the table model
        DefaultTableModel dtm = (DefaultTableModel)jTableResults.getModel();
        // clear table
        dtm.setRowCount(0);
        // iterate the result-array
        for (int cnt=0; cnt<result.length; cnt++) {
            // create a new object
            Object[] ob = new Object[6];
            // store the information in that object
            // first the entry number
            ob[0] = result[cnt];
            // then the entry's title
            ob[1] = dataObj.getZettelTitle(result[cnt]);
            // get timestamp
            String[] timestamp = dataObj.getTimestamp(result[cnt]);
            // init timestamp variables.
            String created = "";
            String edited = "";
            // check whether we have any timestamp at all.
            if (timestamp!=null && !timestamp[0].isEmpty() && timestamp[0].length()>=6) created = timestamp[0].substring(4,6)+"."+timestamp[0].substring(2,4)+".20"+timestamp[0].substring(0,2);
            // check whether we have any timestamp at all.
            if (timestamp!=null && !timestamp[1].isEmpty() && timestamp[1].length()>=6) edited = timestamp[1].substring(4,6)+"."+timestamp[1].substring(2,4)+".20"+timestamp[1].substring(0,2);
            ob[2] = created;
            ob[3] = edited;
            // now, the entry's rating
            ob[4] = dataObj.getZettelRating(result[cnt]);
            // finally, check whether entry is on any desktop, and if so,
            // use desktop name in that column
            ob[5] = desktopObj.getDesktopNameOfEntry(result[cnt]);
            // and add that content as a new row to the table
            dtm.addRow(ob);
        }
        // create a new stringbuilder to prepare the label 
        // that shows the amount of found entries
        StringBuilder sb = new StringBuilder("");
        sb.append("(");
        sb.append(String.valueOf(dtm.getRowCount()));
        sb.append(" ");
        sb.append(resourceMap.getString("hitsText"));
        sb.append(")");
        // set labeltext
        jLabelHits.setText(sb.toString());
        // work done
        tableUpdateActive = false;
        // enable filter text field
        jTextFieldFilterList.setEnabled(true);
    }
}
 
Example 19
Source File: XMBeanAttributes.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
protected void addTableData(DefaultTableModel tableModel,
                            XMBean mbean,
                            MBeanAttributeInfo[] attributesInfo,
                            HashMap<String, Object> attributes,
                            HashMap<String, Object> unavailableAttributes,
                            HashMap<String, Object> viewableAttributes) {

    Object rowData[] = new Object[2];
    int col1Width = 0;
    int col2Width = 0;
    for (int i = 0; i < attributesInfo.length; i++) {
        rowData[0] = (attributesInfo[i].getName());
        if (unavailableAttributes.containsKey(rowData[0])) {
            rowData[1] = Messages.UNAVAILABLE;
        } else if (viewableAttributes.containsKey(rowData[0])) {
            rowData[1] = viewableAttributes.get(rowData[0]);
            if (!attributesInfo[i].isWritable() ||
                !Utils.isEditableType(attributesInfo[i].getType())) {
                rowData[1] = getZoomedCell(mbean, (String) rowData[0], rowData[1]);
            }
        } else {
            rowData[1] = attributes.get(rowData[0]);
        }

        tableModel.addRow(rowData);

        //Update column width
        //
        String str = null;
        if(rowData[0] != null) {
            str = rowData[0].toString();
            if(str.length() > col1Width)
                col1Width = str.length();
        }
        if(rowData[1] != null) {
            str = rowData[1].toString();
            if(str.length() > col2Width)
                col2Width = str.length();
        }
    }
    updateColumnWidth(col1Width, col2Width);
}
 
Example 20
Source File: XMBeanAttributes.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected void addTableData(DefaultTableModel tableModel,
                            XMBean mbean,
                            MBeanAttributeInfo[] attributesInfo,
                            HashMap<String, Object> attributes,
                            HashMap<String, Object> unavailableAttributes,
                            HashMap<String, Object> viewableAttributes) {

    Object rowData[] = new Object[2];
    int col1Width = 0;
    int col2Width = 0;
    for (int i = 0; i < attributesInfo.length; i++) {
        rowData[0] = (attributesInfo[i].getName());
        if (unavailableAttributes.containsKey(rowData[0])) {
            rowData[1] = Messages.UNAVAILABLE;
        } else if (viewableAttributes.containsKey(rowData[0])) {
            rowData[1] = viewableAttributes.get(rowData[0]);
            if (!attributesInfo[i].isWritable() ||
                !Utils.isEditableType(attributesInfo[i].getType())) {
                rowData[1] = getZoomedCell(mbean, (String) rowData[0], rowData[1]);
            }
        } else {
            rowData[1] = attributes.get(rowData[0]);
        }

        tableModel.addRow(rowData);

        //Update column width
        //
        String str = null;
        if(rowData[0] != null) {
            str = rowData[0].toString();
            if(str.length() > col1Width)
                col1Width = str.length();
        }
        if(rowData[1] != null) {
            str = rowData[1].toString();
            if(str.length() > col2Width)
                col2Width = str.length();
        }
    }
    updateColumnWidth(col1Width, col2Width);
}