Java Code Examples for javax.swing.table.AbstractTableModel

The following examples show how to use javax.swing.table.AbstractTableModel. These examples are extracted from open source projects. 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 Project: netbeans   Source File: SchemaPanel.java    License: Apache License 2.0 8 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    //System.out.println("TBALE changed");
    //boolean prefixFlag = false;
    int row = e.getFirstRow();
    int column = e.getColumn();
    AbstractTableModel tblModel = (AbstractTableModel) e.getSource();
    Object data = tblModel.getValueAt(row, column);
    if(column == SCHEMA_COL) {
        SchemaObject rowValue = (SchemaObject)data;
        if(rowValue.toString().equals(startString))
            return;
        String genPrefix = (String) tblModel.getValueAt(row, PREFIX_COL);
        if (genPrefix == null || genPrefix.equals(" ")  ) {
            String prefix = generateUniquePrefix();               
            tableModel.setValueAt(prefix, row, PREFIX_COL);                 
        }
        if(row == tableModel.getRowCount() - 1) {
            addRow(startString);
        }
        //if its the first row, then select it as primary
        if(row == 0) {
           // System.out.println("added first row");
            tblModel.setValueAt(new Boolean(true), 0, 0);
        }
    } 
}
 
Example 2
Source Project: ramus   Source File: QualifierView.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void createInnerComponent() {
    super.createInnerComponent();
    ((AbstractTableModel) component.getTable().getModel())
            .fireTableStructureChanged();
    component.getTable().setLeafIcon(
            new ImageIcon(getClass().getResource(
                    "/com/ramussoft/gui/table/qualifier.png")));
    getComponent().getRowSet().addRowChildListener(new RowChildAdapter() {

        @Override
        public void added(Row parent, Row row, int index) {
            if (parent.getParent() == null)
                return;
            framework.propertyChanged(
                    "CloseQualifier",
                    StandardAttributesPlugin.getQualifierId(engine,
                            parent.getElementId()));
        }
    });
}
 
Example 3
/**
 * Creates an excel table model (either {@link ExcelSheetTableModel} or
 * {@link XlsxSheetTableModel}, depending on file).
 *
 * @param sheetSelection
 *            the Sheet Selection method
 * @param readMode
 *            the read mode for {@link XlsxSheetTableModel} creation. It defines whether only a
 *            preview or the whole sheet content will be loaded
 * @param progressListener
 *            the progress listener to report progress to
 * @return
 * @throws BiffException
 * @throws IOException
 * @throws InvalidFormatException
 */
public AbstractTableModel createExcelTableModel(ExcelSheetSelection sheetSelection, XlsxReadMode readMode, ProgressListener progressListener)
		throws BiffException, IOException, InvalidFormatException, OperatorException, ParseException {
	if (getFile().getAbsolutePath().toLowerCase(Locale.ENGLISH).endsWith(XLSX_FILE_ENDING)) {
		// excel 2007 file
		return new XlsxSheetTableModel(this, sheetSelection, readMode, getFile().getAbsolutePath(), progressListener);
	} else {
		// excel pre 2007 file
		progressListener.setCompleted(50);

		try {
			return new ExcelSheetTableModel(sheetSelection.selectSheetFrom(getOrCreateWorkbookJXL()));
		} catch (ExcelSheetSelection.SheetNotFoundException e) {
			throw new IOException(e);
		}
	}
}
 
Example 4
protected void initTaxonSetsTable(AbstractTableModel tableModel, final String[] columnToolTips) {
    taxonSetsTable = new JTable(tableModel) {
        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };
    taxonSetsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    taxonSetsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            taxonSetsTableSelectionChanged();
        }
    });
    taxonSetsTable.doLayout();
}
 
Example 5
Source Project: openAGV   Source File: ContinuousLoadPanel.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void locationsComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_locationsComboBoxItemStateChanged
  operationTypesComboBox.removeAllItems();
  if (locationsComboBox.getSelectedItem() == null) {
    return;
  }

  TCSObjectReference<Location> loc
      = (TCSObjectReference<Location>) locationsComboBox.getSelectedItem();
  Location location = objectService.fetchObject(Location.class, loc);
  TCSObjectReference<LocationType> locationRef = location.getType();
  LocationType locationType = objectService.fetchObject(LocationType.class, locationRef);
  Set<String> operationTypes = new TreeSet<>(locationType.getAllowedOperations());
  for (String j : operationTypes) {
    operationTypesComboBox.addItem(j);
  }

  // When selecting an item in the locationsComboBox we have
  // to update the vehicle operation in the DriveOrderTable manually,
  // otherwise the old value will persist and that could be a value
  // the new location doesn't support
  int selectedRow = doTable.getSelectedRow();
  if (selectedRow >= 0) {
    DriveOrderTableModel model = (DriveOrderTableModel) doTable.getModel();
    DriveOrderStructure dos = model.getDataAt(selectedRow);
    if (dos != null) {
      if (!operationTypes.isEmpty()) {
        dos.setDriveOrderVehicleOperation(operationTypes.iterator().next());
      }
      else {
        dos.setDriveOrderVehicleOperation(null);
      }
    }
    ((AbstractTableModel) doTable.getModel()).fireTableDataChanged();
  }
}
 
Example 6
Source Project: opt4j   Source File: DefaultTasksPanel.java    License: MIT License 5 votes vote down vote up
@Override
public void startup() {
	this.setLayout(new BorderLayout());

	AbstractTableModel model = getModel();
	table = getTable();
	table.setModel(model);
	table.getColumnModel().getColumn(0).setPreferredWidth(50);
	table.getColumnModel().getColumn(1).setPreferredWidth(500);

	scroll = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

	this.add(scroll, BorderLayout.CENTER);
}
 
Example 7
Source Project: marathonv5   Source File: RTableTest.java    License: Apache License 2.0 5 votes vote down vote up
public void editCell() throws Throwable {
    final JTable table = (JTable) ComponentUtils.findComponent(JTable.class, frame);
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            table.addRowSelectionInterval(2, 2);
            table.addColumnSelectionInterval(2, 2);
            RTable rTable = new RTable(table, null, null, lr);
            rTable.focusGained(null);
            AbstractTableModel model = (AbstractTableModel) table.getModel();
            model.setValueAt("Rowing", 2, 2);
            rTable.focusLost(null);
        }
    });
    List<Call> calls = lr.getCalls();
    Call call = calls.get(1);
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("rows:[2],columns:[Sport]", call.getState());
    call = calls.get(0);
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("Rowing", call.getState());
    AssertJUnit.assertEquals("{2, Sport}", call.getCellinfo());
}
 
Example 8
Source Project: netbeans   Source File: ETableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test that table can be sorted just after a column has been removed. See
 * bug 239045.
 */
public void testRemoveSortedColumn() {
    ETable t = new ETable();
    final int[] size = new int[]{10, 4};
    TableModel tm = new AbstractTableModel() {

        @Override
        public int getRowCount() {
            return size[0];
        }
        
        @Override
        public int getColumnCount() {
            return size[1];
        }
        
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (rowIndex < size[0] && columnIndex < size[1]) {
                return rowIndex;
            } else {
                throw new IndexOutOfBoundsException();
            }
        }
    };
    t.setModel(tm);
    ETableColumnModel etcm = (ETableColumnModel) t.getColumnModel();
    ETableColumn etc = (ETableColumn) etcm.getColumn(3);
    etcm.toggleSortedColumn(etc, true);
    size[1] = 3;
    t.sortAndFilter();
}
 
Example 9
Source Project: netbeans   Source File: InnerTablePanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new InnerTablePanel.
 *
 * @param model DefaultTableModel for included table
 */
public TablePanel(final AbstractTableModel model) {
    super(model);
    final JTable table = getTable();
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeButton.setEnabled(selectedRowCount > 0);
            editButton.setEnabled(selectedRowCount == 1);
        }
    });
}
 
Example 10
Source Project: netbeans   Source File: InnerTablePanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new InnerTablePanel.
 *
 * @param model DefaultTableModel for included table
 */
public TablePanel(final AbstractTableModel model) {
    super(model);
    final JTable table = getTable();
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeButton.setEnabled(selectedRowCount > 0);
            editButton.setEnabled(selectedRowCount == 1);
        }
    });
}
 
Example 11
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 12
public ColUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        String colName, int colIndex, Boolean added) {
    super(model, progress);
    this.colName = colName;
    this.colIndex = colIndex;
    this.added = added;
    this.values = new Object[model.getRowCount()];
    loadValuesFromModel();
}
 
Example 13
public ColUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        int colIndex, Boolean added) {
    super(model, progress);
    this.colName = getModel().getColumnName(colIndex);
    this.colIndex = colIndex;
    this.added = added;
    this.values = new Object[model.getRowCount()];
    loadValuesFromModel();
}
 
Example 14
public ColUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        String colName, Boolean added) {
    super(model, progress);
    this.colName = colName;
    this.colIndex = getModel().findColumn(colName);
    this.added = added;
    this.values = new Object[model.getRowCount()];
    loadValuesFromModel();
}
 
Example 15
public RowUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        int row, Boolean added) {
    super(model, progress);
    this.row = row;
    this.values = new Object[getModel().getColumnCount()];
    for (int i = 0; i < values.length; i++) {
        values[i] = getModel().getValueAt(row, i);
    }
    this.added = added;
}
 
Example 16
public RowUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        int row, Object[] values, Boolean added) {
    super(model, progress);
    this.row = row;
    this.values = values;
    this.added = added;
}
 
Example 17
public CellUndoableEdit(AbstractTableModel model, UndoRedoProgress progress,
        int row, int column, Object oldValue, Object newValue) {
    super(model, progress);
    this.row = row;
    this.column = column;
    this.oldValue = oldValue;
    this.newValue = newValue;
}
 
Example 18
Source Project: jdk8u_jdk   Source File: DrawGridLInesTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 19
public void update() {
	((AbstractTableModel) getModel()).fireTableStructureChanged();
	TableColumnModel columnModel = getColumnModel();
	for (int i = 0; i < columnModel.getColumnCount(); i++) {
		TableColumn tableColumn = columnModel.getColumn(i);
		tableColumn.setPreferredWidth(120);
	}
}
 
Example 20
public void update() {
	((AbstractTableModel) getModel()).fireTableStructureChanged();
	TableColumnModel columnModel = getColumnModel();
	for (int i = 0; i < columnModel.getColumnCount(); i++) {
		TableColumn tableColumn = columnModel.getColumn(i);
		tableColumn.setPreferredWidth(120);
	}
}
 
Example 21
public void update() {
	((AbstractTableModel) getModel()).fireTableStructureChanged();
	TableColumnModel columnModel = getColumnModel();
	for (int i = 0; i < columnModel.getColumnCount(); i++) {
		TableColumn tableColumn = columnModel.getColumn(i);
		tableColumn.setPreferredWidth(120);
	}
}
 
Example 22
Source Project: FoxTelem   Source File: VulcanTab.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void addTables(AbstractTableModel radTableModel, AbstractTableModel radPacketTableModel) {
	super.addTables(radTableModel, radPacketTableModel);
	TableColumn column = null;
	column = table.getColumnModel().getColumn(0);
	column.setPreferredWidth(45);
	
	column = table.getColumnModel().getColumn(1);
	column.setPreferredWidth(55);
	
	for (int i=0; i<58; i++) {
		column = table.getColumnModel().getColumn(i+2);
		column.setPreferredWidth(25);
	}

	column = packetTable.getColumnModel().getColumn(0);
	column.setPreferredWidth(45);
	
	column = packetTable.getColumnModel().getColumn(1);
	column.setPreferredWidth(55);

	column = packetTable.getColumnModel().getColumn(2);
	column.setPreferredWidth(80);

	column = packetTable.getColumnModel().getColumn(3);
	column.setPreferredWidth(70);

	column = packetTable.getColumnModel().getColumn(4);
	column.setPreferredWidth(600);
			
}
 
Example 23
Source Project: FoxTelem   Source File: HerciLSTab.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void addTables(AbstractTableModel radTableModel, AbstractTableModel radPacketTableModel) {
	super.addTables(radTableModel, radPacketTableModel);
	
	TableColumn column = null;
	column = table.getColumnModel().getColumn(0);
	column.setPreferredWidth(45);
	
	column = table.getColumnModel().getColumn(1);
	column.setPreferredWidth(55);
	
	for (int i=0; i<58; i++) {
		column = table.getColumnModel().getColumn(i+2);
		column.setPreferredWidth(25);
	}

	column = packetTable.getColumnModel().getColumn(0);
	column.setPreferredWidth(45);
	
	column = packetTable.getColumnModel().getColumn(1);
	column.setPreferredWidth(55);

	column = packetTable.getColumnModel().getColumn(2);
	column.setPreferredWidth(80);

	column = packetTable.getColumnModel().getColumn(3);
	column.setPreferredWidth(70);

	column = packetTable.getColumnModel().getColumn(4);
	column.setPreferredWidth(600);

	//packetTable.getSelectionModel().addListSelectionListener(this);
	//table.getSelectionModel().addListSelectionListener(this);
	//packetTable.getRowSelectionAllowed();
			
}
 
Example 24
private void initDeck() {
	model = new AbstractTableModel() {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public String getColumnName(int t) {
			if (t == 0)
				return "Card";
			else
				return "Turn " + t;
		}

		@Override
		public Object getValueAt(int r, int c) {
			if (c == 0) {
				return d.getUniqueCards().get(r);
			} else {
				return UITools.roundDouble(calc.getProbability(d,c - 1, d.getUniqueCards().get(r)));
			}
		}

		@Override
		public int getRowCount() {
			return d.getMain().keySet().size();
		}

		@Override
		public int getColumnCount() {
			return maxTurn + 1;
		}
	};

	table.setModel(model);
	model.fireTableDataChanged();
	table.packAll();
}
 
Example 25
public AbstractTableModelAsAbstractColumnTableModelWrapper(
        AbstractTableModel abstractTableModel, List<Column<T>> columns) {
    super();
    this.abstractTableModel = abstractTableModel;
    this.columns = new ArrayList<>(columns);
    this.models = new ArrayList<>();
}
 
Example 26
@Override
public void optionsChanged() {
  myTreeView.getTreeTable().setRowHeight(myChartModel.calculateRowHeight());
  AbstractTableModel model = (AbstractTableModel) myTreeView.getTreeTable().getModel();
  model.fireTableStructureChanged();
  myTreeView.updateUI();
}
 
Example 27
Source Project: intellij-thrift   Source File: ThriftFacetConf.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Generator o = editItem(myType.create());
  if (o == null) return;

  getData().add(o);
  int index = getData().size() - 1;
  ((AbstractTableModel)getTable().getModel()).fireTableRowsInserted(index, index);
  getTable().setRowSelectionInterval(index, index);
}
 
Example 28
Source Project: consulo   Source File: InspectionsConfigTreeTable.java    License: Apache License 2.0 5 votes vote down vote up
public InspectionsConfigTreeTableModel(final InspectionsConfigTreeTableSettings settings, Disposable parentDisposable) {
  super(settings.getRoot());
  mySettings = settings;
  myUpdateRunnable = new Runnable() {
    public void run() {
      settings.updateRightPanel();
      ((AbstractTableModel)myTreeTable.getModel()).fireTableDataChanged();
    }
  };
  myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, parentDisposable);
}
 
Example 29
Source Project: TrakEM2   Source File: FilterEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TableAvailableFilters(final TableChosenFilters tcf) {
	setModel(new AbstractTableModel() {
		@Override
		public Object getValueAt(final int rowIndex, final int columnIndex) {
			return available[rowIndex].getSimpleName();
		}
		@Override
		public int getRowCount() {
			return available.length;
		}
		@Override
		public int getColumnCount() {
			return 1;
		}
		@Override
		public String getColumnName(final int col) {
			return "Available Filters";
		}
	});
	addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(final MouseEvent me) {
			if (2 == me.getClickCount()) {
				tcf.add(available[getSelectedRow()]);
			}
		}
	});
}
 
Example 30
/**
 * Update the table.
 */
private void updateTableGUI() {
  ((AbstractTableModel) table.getModel()).fireTableDataChanged();
  // MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(peakList, true);
}