Search in sources :

Example 26 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project jdk8u_jdk by JetBrains.

the class bug6937798 method createCountryTable.

protected JTable createCountryTable() {
    // Column headers
    final String[] headers = { "Name", "Capital City", "Language(s)", "Monetary Unit(s)", "EC Member" };
    // Table data
    final Object[][] data = { { "Albania", "Tirane", "Albanian, Greek", "Lek", new Boolean(false) }, { "Andorra", "Andorra la Vella", "Catalan, French, Spanish", "French Franc, Spanish Peseta", new Boolean(false) }, { "Austria", "Vienna", "German, Slovenian, Croatian", "Schilling", new Boolean(false) }, { "Belarus", "Minsk", "Byelorussian, Russian", "Belarusian Rubel", new Boolean(false) }, { "Belgium", "Brussels", "French, Flemish, German", "Belgian Franc", new Boolean(true) }, { "Bosnia & Herzegovina", "Sarajevo", "Serbo-Croatian", "Dinar", new Boolean(false) }, { "Bulgaria", "Sofia", "Bulgarian, Turkish", "Lev", new Boolean(false) }, { "Croatia", "Zagreb", "Serbo-Croatian", "Croatian Kuna", new Boolean(false) }, { "Czech Republic", "Prague", "Czech, Slovak", "Koruna", new Boolean(false) }, { "Denmark", "Copenhagen", "Danish", "Krone", new Boolean(true) }, { "Estonia", "Tallinn", "Estonian, Latvian, Lithuanian, Russian", "Estonian Kroon", new Boolean(false) }, { "Finland", "Helsinki", "Finnish, Swedish, Lappish", "Markka", new Boolean(false) }, { "France", "Paris", "French", "Franc", new Boolean(true) }, { "Germany", "Berlin", "German", "Deutsche Mark", new Boolean(true) }, { "Greece", "Athens", "Greek, English, French", "Drachma", new Boolean(true) }, { "Hungary", "Budapest", "Hungarian", "Forint", new Boolean(false) }, { "Iceland", "Reykjavik", "Icelandic", "Icelandic Krona", new Boolean(false) }, { "Ireland", "Dublin", "Irish, English", "Pound", new Boolean(true) }, { "Italy", "Rome", "Italian", "Lira", new Boolean(true) }, { "Latvia", "Riga", "Lettish, Lithuanian, Russian", "Lat", new Boolean(false) }, { "Liechtenstein", "Vaduz", "German", "Swiss Franc", new Boolean(false) }, { "Lithuania", "Vilnius", "Lithuanian, Polish, Russian", "Lita", new Boolean(false) }, { "Luxembourg", "Luxembourg", "French, German, Letzeburgesch", "Luxembourg Franc", new Boolean(true) }, { "Macedonia", "Skopje", "Macedonian, Albanian, Turkish, Serbo-Croatian", "Denar", new Boolean(false) }, { "Malta", "Valletta", "Maltese, English", "Maltese Lira", new Boolean(false) }, { "Moldova", "Chisinau", "Moldovan, Russian", "Leu", new Boolean(false) }, { "Monaco", "Monaco", "French, English, Italian", "French Franc", new Boolean(false) }, { "the Netherlands", "Amsterdam", "Dutch", "Guilder", new Boolean(true) }, { "Norway", "Oslo", "Norwegian", "Krone", new Boolean(false) }, { "Poland", "Warsaw", "Polish", "Zloty", new Boolean(false) }, { "Portugal", "Lisbon", "Portuguese", "Escudo", new Boolean(true) }, { "Romania", "Bucharest", "Romanian", "Leu", new Boolean(false) }, { "Russia", "Moscow", "Russian", "Ruble", new Boolean(false) }, { "San Marino", "San Marino", "Italian", "Italian Lira", new Boolean(false) }, { "Slovakia", "Bratislava", "Slovak, Hungarian", "Koruna", new Boolean(false) }, { "Slovenia", "Ljubljana", "Slovenian, Serbo-Croatian", "Tolar", new Boolean(false) }, { "Spain", "Madrid", "Spanish", "Peseta", new Boolean(true) }, { "Sweden", "Stockholm", "Swedish", "Krona", new Boolean(false) }, { "Switzerland", "Bern", "German, French, Italian", "Swiss Franc", new Boolean(false) }, { "Turkey", "Ankara", "Turkish", "Turkish Lira", new Boolean(false) }, { "Ukraine", "Kiev", "Ukranian, Russian, Romanian, Polish, Hungarian", "Hryvnia", new Boolean(false) }, { "United Kingdom", "London", "English, Welsh", "British Pound", new Boolean(true) }, { "Yugoslavia", "Belgrade", "Serbo-Croatian, Slovenian, Macedonian", "Dinar", new Boolean(false) } };
    // Table model
    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return headers.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        public String getColumnName(int column) {
            return headers[column];
        }

        public Class getColumnClass(int col) {
            return getValueAt(0, col).getClass();
        }

        public void setValueAt(Object aValue, int row, int column) {
            data[row][column] = aValue;
        }

        public boolean isCellEditable(int row, int col) {
            return (col == 4);
        }
    };
    // Create table with table model
    JTable countryTable = new JTable(dataModel);
    countryTable.setGridColor(Color.pink);
    countryTable.setBackground(Color.white);
    countryTable.setForeground(Color.black);
    return countryTable;
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 27 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project jdk8u_jdk by JetBrains.

the class bug6777378 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(20);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            try {
                UIManager.setLookAndFeel(new MetalLookAndFeel());
            } catch (Exception e) {
                e.printStackTrace();
            }
            JTable table = new JTable(new AbstractTableModel() {

                public int getRowCount() {
                    return 10;
                }

                public int getColumnCount() {
                    return 10;
                }

                public Object getValueAt(int rowIndex, int columnIndex) {
                    return "" + rowIndex + " " + columnIndex;
                }
            });
            header = new JTableHeader(table.getColumnModel());
            header.setToolTipText("hello");
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(header);
            frame.setSize(300, 300);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point point = header.getLocationOnScreen();
    robot.mouseMove(point.x + 20, point.y + 50);
    robot.mouseMove(point.x + 30, point.y + 50);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
Also used : SunToolkit(sun.awt.SunToolkit) JTableHeader(javax.swing.table.JTableHeader) AbstractTableModel(javax.swing.table.AbstractTableModel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel)

Example 28 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project jabref by JabRef.

the class IntegrityCheckAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
    List<IntegrityMessage> messages = check.checkBibtexDatabase();
    if (messages.isEmpty()) {
        JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
    } else {
        Map<String, Boolean> showMessage = new HashMap<>();
        // prepare data model
        Object[][] model = new Object[messages.size()][4];
        int i = 0;
        for (IntegrityMessage message : messages) {
            model[i][0] = message.getEntry().getId();
            model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
            model[i][2] = message.getFieldName();
            model[i][3] = message.getMessage();
            showMessage.put(message.getMessage(), true);
            i++;
        }
        // construct view
        JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
        // hide IDs
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.removeColumn(columnModel.getColumn(0));
        RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {

            @Override
            public boolean include(Entry<?, ?> entry) {
                return showMessage.get(entry.getStringValue(3));
            }
        };
        TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
        sorter.setRowFilter(filter);
        table.setRowSorter(sorter);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setDefaultEditor(Object.class, null);
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.addListSelectionListener(event -> {
            if (!event.getValueIsAdjusting()) {
                try {
                    String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
                    String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
                    frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
                } catch (ArrayIndexOutOfBoundsException exception) {
                }
            }
        });
        // BibTeX key
        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        // field name
        table.getColumnModel().getColumn(1).setPreferredWidth(60);
        // message
        table.getColumnModel().getColumn(2).setPreferredWidth(400);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        JScrollPane scrollPane = new JScrollPane(table);
        String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
        JDialog dialog = new JDialog(frame, title, false);
        JPopupMenu menu = new JPopupMenu();
        for (String messageString : showMessage.keySet()) {
            JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
            menuItem.addActionListener(event -> {
                showMessage.put(messageString, menuItem.isSelected());
                ((AbstractTableModel) table.getModel()).fireTableDataChanged();
            });
            menu.add(menuItem);
        }
        JButton menuButton = new JButton(Localization.lang("Filter"));
        menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
        FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));
        builder.add(scrollPane).xy(1, 1);
        builder.add(menuButton).xy(1, 3, "c, b");
        dialog.add(builder.getPanel());
        dialog.setSize(600, 600);
        // show view
        dialog.setVisible(true);
    }
}
Also used : HashMap(java.util.HashMap) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) IntegrityCheck(org.jabref.logic.integrity.IntegrityCheck) IntegrityMessage(org.jabref.logic.integrity.IntegrityMessage) RowFilter(javax.swing.RowFilter) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) ListSelectionModel(javax.swing.ListSelectionModel) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) JDialog(javax.swing.JDialog)

Example 29 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project processdash by dtuma.

the class TaskScheduleDialog method handleEvNodeChanged.

private void handleEvNodeChanged(EVTask node) {
    try {
        TreePath tp = new TreePath(node.getPath());
        int row = treeTable.getTree().getRowForPath(tp);
        if (row != -1) {
            AbstractTableModel model = (AbstractTableModel) treeTable.getModel();
            model.fireTableChanged(new TableModelEvent(model, row));
        }
    } catch (Exception e) {
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TableModelEvent(javax.swing.event.TableModelEvent) AbstractTableModel(javax.swing.table.AbstractTableModel) Point(java.awt.Point) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) MalformedURLException(java.net.MalformedURLException)

Example 30 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project vcell by virtualcell.

the class FRAPEstimationPanel_NotUsed method initTable.

private void initTable() {
    TableModel tableModel = new AbstractTableModel() {

        public String getColumnName(int col) {
            return FRAP_ESTIMATE_COLUMN_NAMES[col].toString();
        }

        public int getRowCount() {
            return FRAPParameterEstimateEnum.values().length;
        }

        public int getColumnCount() {
            return FRAP_ESTIMATE_COLUMN_NAMES.length;
        }

        public Object getValueAt(int row, int col) {
            if (col == PARAMETER_TYPE_COLUMN) {
                return FRAPParameterEstimateEnum.values()[row].parameterTypeName;
            } else if (col == UNIT_COLUMN) {
                return FRAPParameterEstimateEnum.values()[row].unit;
            }
            return FRAPParameterEstimateEnum.values()[row].value;
        }

        public boolean isCellEditable(int row, int col) {
            return false;
        }

        public void setValueAt(Object value, int row, int col) {
            if (col == PARAMETER_TYPE_COLUMN || col == UNIT_COLUMN) {
                throw new IllegalArgumentException("Can't update 'Parameter Type' or 'Unit' column");
            }
            FRAPParameterEstimateEnum.values()[row].value = (Double) value;
            fireTableCellUpdated(row, col);
        }
    };
    table.setModel(tableModel);
    table.getTableHeader().getColumnModel().getColumn(UNIT_COLUMN).setMaxWidth(50);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)31 TableModel (javax.swing.table.TableModel)8 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)4 JTable (javax.swing.JTable)4 JBTable (com.intellij.ui.table.JBTable)3 JFrame (javax.swing.JFrame)3 JScrollPane (javax.swing.JScrollPane)3 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 TableModelEvent (javax.swing.event.TableModelEvent)2 TableRowSorter (javax.swing.table.TableRowSorter)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 Point (java.awt.Point)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 MouseEvent (java.awt.event.MouseEvent)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1