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

The following examples show how to use javax.swing.table.DefaultTableModel#addColumn() . 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: OldJTable.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 2
Source File: OldJTable.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 3
Source File: UpdateTableDialog.java    From AndroidDBvieweR with Apache License 2.0 6 votes vote down vote up
public UpdateTableDialog(java.awt.Frame parent, boolean modal, String outputResult, String tableName, Object[] columnNames) {
    super(parent, modal);
    initComponents();
    this.outputResult = outputResult;
    this.tableName = tableName;
    this.columnNames = columnNames;
    this.mainFrame = (MainFrame) parent;
    setTitle("Update table `" + tableName + "`");
    setLocationRelativeTo(null);
    resultTable.setModel(new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

    });
    resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    defaultTableModel = (DefaultTableModel) resultTable.getModel();
    for (Object columnName : columnNames) {
        defaultTableModel.addColumn(columnName);
    }
    tableColumnAdjuster = new TableColumnAdjuster(resultTable);

    processResult();
}
 
Example 4
Source File: OldJTable.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 5
Source File: DataSchemaCompilerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testDataSchemaForPlainIndexTables() throws ReportDataFactoryException {
  final DefaultTableModel model = new DefaultTableModel();
  model.addColumn( "Test" );
  model.addColumn( "Test2" );

  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();

  final DataSchemaDefinition schemaDefinition = DataSchemaUtility.parseDefaults( mgr );
  final DataSchemaCompiler compiler =
      new DataSchemaCompiler( schemaDefinition, new DefaultDataAttributeContext(), mgr );
  final DataSchema compiledSchema = compiler.compile( new IndexedTableModel( model ) );
  final DataAttributes attributes = compiledSchema.getAttributes( "::column::0" );
  assertNotNull( attributes );
  assertEquals( "Test", attributes.getMetaAttribute( MetaAttributeNames.Formatting.NAMESPACE,
      MetaAttributeNames.Formatting.LABEL, String.class, new DefaultDataAttributeContext() ) );

  final DataAttributes attributes2 = compiledSchema.getAttributes( "::column::1" );
  assertNotNull( attributes2 );
  assertEquals( "Test2", attributes2.getMetaAttribute( MetaAttributeNames.Formatting.NAMESPACE,
      MetaAttributeNames.Formatting.LABEL, String.class, new DefaultDataAttributeContext() ) );
}
 
Example 6
Source File: OldJTable.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 7
Source File: OldJTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 8
Source File: OldJTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 9
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 10
Source File: OldJTable.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 11
Source File: AbstractTableGroupPanel.java    From EasyCode with MIT License 6 votes vote down vote up
/**
 * 初始化方法
 */
protected void init() {
    initFlag = false;
    //初始化分组
    initGroup();
    //初始化列
    columnConfigInfo = initColumn();
    tableModel = new DefaultTableModel();
    for (ColumnConfig column : columnConfigInfo) {
        tableModel.addColumn(column.getTitle());
    }
    //初始化数据
    getCurrGroup().getElementList().forEach(e -> {
        tableModel.addRow(toRow(e));
    });
    table.setModel(tableModel);
    refreshEditorType();
    initFlag = true;
}
 
Example 12
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 13
Source File: SunJVMFieldsPanel.java    From jsonde with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JTable getVirtualMachineTable() {
    DefaultTableModel vmTableModel = new DefaultTableModel();

    vmTableModel.addColumn("PID");
    vmTableModel.addColumn("Application");

    try {

        VirtualMachineService vmService = VirtualMachineService.getInstance();

        for (VirtualMachineData vmData : vmService.getVirtualMachines()) {

            vmTableModel.addRow(new Object[]{
                    vmData.getId(),
                    vmData.getDescription()
            });

        }

    } catch (VirtualMachineServiceException e) {
        Main.getInstance().processException(e);
    }

    JTable vmTable = new JTable(vmTableModel);
    return vmTable;
}
 
Example 14
Source File: PercentageDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a sample dataset. <!-- (Used in JUnitTest) -->
 *
 * @return A <code>TableModel</code>.
 */
public static TableModel createData()
{
  final DefaultTableModel data = new DefaultTableModel();
  data.addColumn("A");
  data.addColumn("B");
  data.addRow(new Object[]{new Double(43.0), new Double(127.5)});
  data.addRow(new Object[]{new Double(57.0), new Double(108.5)});
  data.addRow(new Object[]{new Double(35.0), new Double(164.8)});
  data.addRow(new Object[]{new Double(86.0), new Double(164.0)});
  data.addRow(new Object[]{new Double(12.0), new Double(103.2)});
  return data;
}
 
Example 15
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: CsvTableEditorSwing.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateUIComponents() {
    CsvFile csvFile = getCsvFile();
    if (csvFile == null) {
        return;
    }

    CsvColumnInfoMap<PsiElement> columnInfoMap = csvFile.getColumnInfoMap();
    if (Objects.equals(lastColumnInfoMap, columnInfoMap)) {
        return;
    }

    lastColumnInfoMap = columnInfoMap;
    updateInteractionElements();
    DefaultTableModel tableModel = new DefaultTableModel(0, 0);
    if (!columnInfoMap.hasErrors()) {
        int startRow = getFileEditorState().getFixedHeaders() ? 1 : 0;
        for (int columnIndex = 0; columnIndex < columnInfoMap.getColumnInfos().size(); ++columnIndex) {
            CsvColumnInfo<PsiElement> columnInfo = columnInfoMap.getColumnInfo(columnIndex);
            List<PsiElement> elements = columnInfo.getElements();
            if (columnIndex == 0 && CsvEditorSettings.getInstance().isFileEndLineBreak() &&
                    lastColumnInfoMap.hasEmptyLastLine()) {
                elements.remove(elements.size() - 1);
            }

            tableModel.addColumn(String.format("Column %s (%s entries)", columnIndex + 1, elements.size()),
                    elements.stream()
                            .skip(startRow)
                            .map(psiElement -> psiElement == null ? "" : CsvHelper.unquoteCsvValue(psiElement.getText(), currentEscapeCharacter))
                            .collect(Collectors.toList()).toArray(new String[0]));
        }
    }
    Object[][] values = getTableComponentData(tableModel, true);
    updateTableComponentData(dataManagement.addState(values));
}
 
Example 17
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 18
Source File: ScrPhonology.java    From PolyGlot with MIT License 5 votes vote down vote up
private void setupRomTable() {
    DefaultTableModel romTableModel = new DefaultTableModel();
    romTableModel.addColumn("Character(s)");
    romTableModel.addColumn("Romanization");
    tblRom.setModel(romTableModel); // TODO: find way to make rom display RTL order when appropriate Maybe something on my custom cell editor
    
    boolean useConFont = !core.getPropertiesManager().isOverrideRegexFont();

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

    column = tblRom.getColumnModel().getColumn(1);
    column.setCellEditor(new PCellEditor(false, core));
    column.setCellRenderer(new PCellRenderer(false, core));

    // disable tab/arrow selection
    InputMap procInput = tblRom.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_DOWN_MASK), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_DOWN_MASK), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_DOWN_MASK), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "none");
    procInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_DOWN_MASK), "none");
}
 
Example 19
Source File: ScrLogoDetails.java    From PolyGlot with MIT License 4 votes vote down vote up
/**
 * populates all properties of given logograph at index
 *
 * @param index index to populate props from
 */
private void populateLogoProps(int index) {
    if (curPopulating) {
        return;
    }

    curPopulating = true;

    if (index == -1) {
        txtName.setText("");
        txtNotes.setText("");
        txtStrokes.setText("");
        lstRadicals.setModel(new DefaultListModel<>());
        tblReadings.setModel(new DefaultTableModel(new Object[]{"Readings"}, 0));
        lstRelWords.setModel(new DefaultListModel<>());
        chkIsRad.setSelected(false);
        lblLogo.setIcon(new ImageIcon(new LogoNode().getLogoGraph().getScaledInstance(
                lblLogo.getWidth(), lblLogo.getHeight(), Image.SCALE_SMOOTH)));
        populateRelatedWords();
        setEnableControls(false);

        curPopulating = false;
        return;
    }

    LogoNode curNode = (LogoNode) lstLogos.getModel().getElementAt(index);

    txtName.setText(curNode.getValue());
    txtNotes.setText(curNode.getNotes());
    txtStrokes.setText(String.valueOf(curNode.getStrokes()));
    chkIsRad.setSelected(curNode.isRadical());

    // Populate radicals
    DefaultListModel<Object> radModel = new DefaultListModel<>();

    for (LogoNode radNode : curNode.getRadicals()) {
        try {
            radModel.addElement(radNode);
        } catch (Exception e) {
            // do nothing
            IOHandler.writeErrorLog(e);
        }
    }

    lstRadicals.setModel(radModel);
    
    // TODO: figure out a way to make this respect RTL languages... maybe just insert char here? and cut at save time? Messy but effective...
    // Populate readings
    DefaultTableModel procModel = new DefaultTableModel();
    procModel.addColumn("Readings");
    tblReadings.setModel(procModel);

    // Fonts must be set each time the table is rebuilt
    TableColumn column = tblReadings.getColumnModel().getColumn(0);
    column.setCellEditor(new PCellEditor(true, core));
    column.setCellRenderer(new PCellRenderer(true, core));

    for (String curProc : curNode.getReadings()) {
        Object[] newRow = {curProc};
        procModel.addRow(newRow);
    }
    tblReadings.setModel(procModel);

    // set logograph picture
    lblLogo.setIcon(new ImageIcon(curNode.getLogoGraph().getScaledInstance(
            lblLogo.getWidth(), lblLogo.getHeight(), Image.SCALE_SMOOTH)));

    populateRelatedWords();
    setEnableControls(true);

    curPopulating = false;
}
 
Example 20
Source File: HeapProfilerView.java    From jsonde with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
public HeapProfilerView(Client client) {

        this.client = client;

        DefaultTableModel tableModel = new DefaultTableModel();

        tableModel.addColumn("Class name");
        tableModel.addColumn("Instances Count");
        tableModel.addColumn("Collected Instances Count");
        tableModel.addColumn("Total Size");

        try {

            for (Clazz clazz : DaoFactory.getClazzDao().getByCondition("CREATECOUNTER > 0 ORDER BY TOTALCURRENTSIZE DESC")) {

                tableModel.addRow(new Object[]{
                        clazz.getName(),
                        clazz.getCreateCounter() - clazz.getCollectCounter(),
                        clazz.getCollectCounter(),
                        clazz.getTotalCurrentSize()
                });

            }

        } catch (DaoException e) {
            Main.getInstance().processException(e);
        }

        JTable table = new JTable(tableModel);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setViewportView(table);

        setLayout(new BorderLayout());

        add(scrollPane, BorderLayout.CENTER);


    }