Package javax.swing.table

Examples of javax.swing.table.TableModel


                if (ev.isPopupTrigger())
                {
                    JPopupMenu menu = new JPopupMenu();
                    final MouseEvent mouseEv = ev;
                    JStatusMenuItem menuItem;
                    final TableModel tblModel = m_table.getModel();
                    if (tblModel.getColumnCount() != m_table.getColumnCount())
                    {
                        menuItem = new JStatusMenuItem(Main.getString("menu_tableheader_add"), Main.getString("statusbar_menutableheader_add_help"), m_statusBar);
                        menu.add(menuItem);
                        menuItem.addActionListener(new ActionListener()
                        {
                            public void actionPerformed (ActionEvent ev)
                            {
                                int i, anzahl = tblModel.getColumnCount(), colIndex, index = 0;
                                JColChooserData[] dataArray = new JColChooserData[anzahl - m_table.getColumnCount()];
                                for (i=0; i<anzahl; i++)
                                {
                                    colIndex = m_table.convertColumnIndexToView(i);
                                    if (colIndex == -1)
                                        dataArray[index++] = new JColChooserData(tblModel.getColumnName(i), i);
                                }
                                JColChooserDialog dia = new JColChooserDialog(Main.m_mainFrame, dataArray);
                                dia.setVisible(true);
                                if (dia.isOk())
                                {
View Full Code Here


     * @param charset Charset encoding for the file
     * @param columnsToExport Indicates the indexes of the columns to export. All columns will be exported if null
     * @throws IOException When an error happens while writing the file
     */
    public static void writeCSVFile(JTable table, File file, Character separator, Charset charset, Integer[] columnsToExport) throws IOException {
        TableModel model = table.getModel();
        FileOutputStream out = new FileOutputStream(file);
        if (separator == null) {
            separator = DEFAULT_SEPARATOR;
        }

        if (columnsToExport == null) {
            columnsToExport = new Integer[model.getColumnCount()];
            for (int i = 0; i < columnsToExport.length; i++) {
                columnsToExport[i] = i;
            }
        }

        CsvWriter writer = new CsvWriter(out, separator, charset);

        //Write column headers:
        for (int column = 0; column < columnsToExport.length; column++) {
            writer.write(model.getColumnName(columnsToExport[column]), true);
        }
        writer.endRecord();

        //Write rows:
        Object value;
        String text;
        for (int row = 0; row < table.getRowCount(); row++) {
            for (int column = 0; column < columnsToExport.length; column++) {
                value = model.getValueAt(table.convertRowIndexToModel(row), columnsToExport[column]);
                if (value != null) {
                    text = value.toString();
                } else {
                    text = "";
                }
View Full Code Here

        NbPreferences.forModule(CSVExportUI.class).putInt(SEPARATOR_SAVED_PREFERENCES, separatorComboBox.getSelectedIndex());
    }

    private void refreshColumns() {
        boolean outlineTable = table instanceof Outline;
        TableModel model = table.getModel();
        columnsCheckBoxes = new JCheckBox[model.getColumnCount()];
        columnsPanel.removeAll();
        columnsPanel.setLayout(new MigLayout("", "[pref!]"));


        int modelIndex;
        //Show rest of columns:
        for (int i = 0; i < table.getColumnCount(); i++) {
            modelIndex=table.convertColumnIndexToModel(i);
            if(modelIndex==0){
                if(outlineTable){//If outline table, hide nodes tree column from exporting (first column)
                    columnsCheckBoxes[i] = new JCheckBox(model.getColumnName(modelIndex), false);
                    continue;
                }
            }
            columnsCheckBoxes[i] = new JCheckBox(model.getColumnName(modelIndex), true);
            columnsPanel.add(columnsCheckBoxes[i], "wrap");
        }
        columnsPanel.revalidate();
        columnsPanel.repaint();
    }
View Full Code Here

            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            int idx = lsm.getMinSelectionIndex();
            if (idx >= 0) {
                try {
                    idx = table.getRowSorter().convertRowIndexToModel(idx);
                    TableModel tm = ((RequestTrackerFile) table.getModel()).getData(idx);
                    if (dataField == null) {
                        dataField = new JTable();
                        dataField.setAutoCreateRowSorter(true);
                        dataField.setGridColor(Color.GRAY);
                        dataField.setShowGrid(true);
View Full Code Here

            label.setHorizontalAlignment(LEFT);
            label.setForeground(LightZoneSkin.Colors.ToolPanesForeground);
        }
        // label.setMaximumSize(new Dimension(100, 20));

        TableModel model = table.getModel();
        if (model.isCellEditable(row, column)) {
            // Some cells get a background to show they are editable.
            label.setBackground(LightZoneSkin.Colors.FrameBackground);
        }
        else {
            label.setBackground(LightZoneSkin.Colors.ToolPanesBackground);
View Full Code Here

            if (model == null) {
                throw new IllegalArgumentException("Cannot set a null TableModel");
            }
           
            if (this.model != model) {
                TableModel old = this.model;
                if (old != null) {
                    old.removeTableModelListener(this);
                }
                this.model = model;
                model.addTableModelListener(this);

            }
View Full Code Here

      {ctrl+'+'+leftClick, LangTool.INSTANCE.getString19("ShortcutsFrame.26"), catDraw}, //$NON-NLS-1$
      {shift+'+'+leftClick, LangTool.INSTANCE.getString19("ShortcutsFrame.27"), catDraw}, //$NON-NLS-1$
      {ctrl+'+'+LangTool.INSTANCE.getString19("ShortcutsFrame.29"), LangTool.INSTANCE.getString19("ShortcutsFrame.30"), catDraw} //$NON-NLS-1$ //$NON-NLS-2$
    };

        final TableModel dataModel = new AbstractTableModel() {
      private static final long serialVersionUID = 1L;
      @Override
      public int getColumnCount() { return titles.length; }
            @Override
      public int getRowCount() { return data.length;}
View Full Code Here

    m_instances = new Instances(insts);
    m_simpleConfigPanel.setInstances(insts);
    m_advancedConfigPanel.setInstances(insts);
   
    if (first) {           
      TableModel model = m_simpleConfigPanel.m_targetPanel.getTableModel();
      model.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
          int[] selected = m_simpleConfigPanel.m_targetPanel.getSelectedAttributes();
          if (selected != null && selected.length > 0) {
            m_startBut.setEnabled(true);
          } else {
View Full Code Here

        reallocateIndexes();
    }

    public int compareRowsByColumn(int row1, int row2, int column) {
        //Class type = model.getColumnClass(column);
        TableModel data = model;

        // Check for nulls.

        Object o1 = data.getValueAt(row1, column);
        Object o2 = data.getValueAt(row2, column);

        // If both values are null, return 0.
        if (o1 == null && o2 == null) {
            return 0;
        } else if (o1 == null) { // Define null less than everything.
            return -1;
        } else if (o2 == null) {
            return 1;
        }
       
        if(o1.getClass() != o2.getClass())
          return -1;
        Class type=o1.getClass();
       
        /*
         * We copy all returned values from the getValue call in case
         * an optimised model is reusing one object to return many
         * values.  The Number subclasses in the JDK are immutable and
         * so will not be used in this way but other subclasses of
         * Number might want to do this to save space and avoid
         * unnecessary heap allocation.
         */

        if (type.getSuperclass() == java.lang.Number.class) {
            Number n1 = (Number)data.getValueAt(row1, column);
            double d1 = n1.doubleValue();
            Number n2 = (Number)data.getValueAt(row2, column);
            double d2 = n2.doubleValue();

            if (d1 < d2) {
                return -1;
            } else if (d1 > d2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == java.util.Date.class) {
            Date d1 = (Date)data.getValueAt(row1, column);
            long n1 = d1.getTime();
            Date d2 = (Date)data.getValueAt(row2, column);
            long n2 = d2.getTime();

            if (n1 < n2) {
                return -1;
            } else if (n1 > n2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == String.class) {
            String s1 = (String)data.getValueAt(row1, column);
            String s2    = (String)data.getValueAt(row2, column);
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
            } else if (result > 0) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == Boolean.class) {
            Boolean bool1 = (Boolean)data.getValueAt(row1, column);
            boolean b1 = bool1.booleanValue();
            Boolean bool2 = (Boolean)data.getValueAt(row2, column);
            boolean b2 = bool2.booleanValue();

            if (b1 == b2) {
                return 0;
            } else if (b1) { // Define false < true
                return 1;
            } else {
                return -1;
            }
        } else {
            Object v1 = data.getValueAt(row1, column);
            String s1 = v1.toString();
            Object v2 = data.getValueAt(row2, column);
            String s2 = v2.toString();
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
View Full Code Here

    public void processInput(BridgeComponentPeer peer, BridgeInputContext context, Map inputForm) throws InputException
    {
        if (hasEvent(peer, inputForm)) //quick check for table visibility
        {
            JTable table = (JTable) peer.getComponentObject();
            TableModel model = table.getModel();
            int rows = table.getRowCount();
            //          handle selection
            if ("select".equals(inputForm.get(peer.getId() + "-action")))
            {
                String value = (String) inputForm.get(peer.getId());
View Full Code Here

TOP

Related Classes of javax.swing.table.TableModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.