本文整理汇总了Java中javax.swing.table.TableModel类的典型用法代码示例。如果您正苦于以下问题:Java TableModel类的具体用法?Java TableModel怎么用?Java TableModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableModel类属于javax.swing.table包,在下文中一共展示了TableModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import javax.swing.table.TableModel; //导入依赖的package包/类
private void validate(int viewRow, int viewCol) {
JTable table = (JTable) getComponent();
try {
int row = table.convertRowIndexToModel(viewRow);
int col = table.convertColumnIndexToModel(viewCol);
TableModel model = table.getModel();
if (row >= 0 && row < model.getRowCount() && col >= 0 && col < model.getColumnCount()) {
if (table.isCellEditable(viewRow, viewCol)) {
return;
} else {
throw new NoSuchElementException("The cell is not editable on JTable: (" + viewRow + ", " + viewCol + ")",
null);
}
}
} catch (IndexOutOfBoundsException e) {
}
throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null);
}
示例2: saveProperties
import javax.swing.table.TableModel; //导入依赖的package包/类
private boolean saveProperties() {
final Map<String, Object> properties = new HashMap<String, Object>();
final TableModel model = table.getModel();
if (model.getColumnCount() == 2) {
for (int i = 0; i < model.getRowCount(); i++) {
final String key = (String) model.getValueAt(i, 0);
final Object value = model.getValueAt(i, 1);
if (properties.containsKey(key)) {
return false;
} else {
properties.put(key, value);
}
}
sourceFile.setProperties(properties);
return true;
} else {
return false;
}
}
示例3: setModel
import javax.swing.table.TableModel; //导入依赖的package包/类
@Override
public void setModel(TableModel dataModel) {
super.setModel(dataModel);
if (!(dataModel instanceof TableEditorModel))
return;
TableEditorModel model = (TableEditorModel) dataModel;
Engine engine = framework.getEngine();
AccessRules rules = framework.getAccessRules();
for (int i = 0; i < plugins.length; i++) {
AttributePlugin plugin = framework.findAttributePlugin(attributes
.get(i));
plugins[i] = plugin;
cellEditors[i] = plugin.getTableCellEditor(engine, rules,
attributes.get(i));
if (cellEditors[i] == null) {
cellEditors[i] = new DialogedTableCellEditor(engine, rules,
attributes.get(i), plugins[i], framework);
model.setSaveValue(i, false);
}
cellRenderers[i] = plugin.getTableCellRenderer(engine, rules,
attributes.get(i));
}
}
示例4: createRawTable
import javax.swing.table.TableModel; //导入依赖的package包/类
public static JTable createRawTable(TableModel model)
{
JTable table = new JTable(model)
{
@Override
public boolean getScrollableTracksViewportHeight()
{
// fetch the table's parent
Container viewport = getParent();
// if the parent is not a viewport, calling this isn't useful
if( !(viewport instanceof JViewport) )
{
return false;
}
// return true if the table's preferred height is smaller
// than the viewport height, else false
return getPreferredSize().height < viewport.getHeight();
}
};
return table;
}
示例5: setTableModel
import javax.swing.table.TableModel; //导入依赖的package包/类
public void setTableModel(TableModel model) {
if (model == null) {
table.clearSelection();
table.setModel(new DefaultTableModel());
removeAll();
add(noDataContainer, BorderLayout.CENTER);
} else {
int selectedRow = getSelectedRow();
table.setModel(model);
if (selectedRow != -1)
table.getSelectionModel().setSelectionInterval(selectedRow,
selectedRow);
removeAll();
add(dataContainer, BorderLayout.CENTER);
}
validate();
repaint();
}
示例6: getAllShortcutsForAction
import javax.swing.table.TableModel; //导入依赖的package包/类
public Vector<String> getAllShortcutsForAction(String actionName) {
System.out.println("[TEST_DEBUG]");
System.out.println("[TEST_DEBUG] ### Examining all shortcuts for action: " + actionName);
Vector<String> lstr = new Vector<String>();
String tmpStr = actionSearchByName().getText();
searchActionName(actionName);
TableModel tm = getActionsTableModel();
String _str;
String _scStr;
for (int i = 0; i < tm.getRowCount(); i++) {
_str = tm.getValueAt(i, 0).toString();
if (_str.toLowerCase().equals(actionName.toLowerCase()) || _str.toLowerCase().equals(actionName.toLowerCase() + " (alternative shortcut)")) {
_scStr = tm.getValueAt(i, 1).toString().toLowerCase();
lstr.add(_scStr);
System.out.println("[TEST_DEBUG] -> found action \"" + _str + "\" with shortcut " + _scStr);
}
}
searchActionName(tmpStr);
System.out.println("[TEST_DEBUG] ### Examining all shortcuts done");
return lstr;
}
示例7: retrievedParcelOperations
import javax.swing.table.TableModel; //导入依赖的package包/类
public List<ParcelOperationDAO> retrievedParcelOperations(){
hasBeenEdited = false;
List<ParcelOperationDAO> ops = new LinkedList<>();
TableModel model = table.getModel();
if (model.getRowCount() != parcelOperations.size()) {
hasBeenEdited = true;
}
for (int i = 0; i < model.getRowCount(); i++){
String parcelOperation = (String) model.getValueAt(i, 0);
Object parcelValue = model.getValueAt(i, 1);
String originalOperation = parcelOperations.get(i).parcelType;
Object originalValue = parcelOperations.get(i).value;
if (parcelValue == null && originalValue == null) {
ops.add(parcelOperations.get(i));
} else if (parcelValue == null || originalValue == null) {
hasBeenEdited = true;
ops.add(new ParcelOperationDAO(parcelOperation, parcelValue));
} else if (!originalOperation.equals(parcelOperation) || !originalValue.equals(parcelValue)) {
hasBeenEdited = true;
ops.add(new ParcelOperationDAO(parcelOperation, parcelValue));
} else {
ops.add(parcelOperations.get(i));
}
}
return ops;
}
示例8: autoSizeTableColumns
import javax.swing.table.TableModel; //导入依赖的package包/类
public static void autoSizeTableColumns(JTable table) {
TableModel model = table.getModel();
TableColumn column = null;
Component comp = null;
int headerWidth = 0;
int maxCellWidth = Integer.MIN_VALUE;
int cellWidth = 0;
TableCellRenderer headerRenderer =
table.getTableHeader().getDefaultRenderer();
for (int i = 0; i < table.getColumnCount(); i++) {
column = table.getColumnModel().getColumn(i);
comp = headerRenderer.getTableCellRendererComponent(table,
column.getHeaderValue(), false, false, 0, 0);
headerWidth = comp.getPreferredSize().width + 10;
maxCellWidth = Integer.MIN_VALUE;
for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
TableCellRenderer r = table.getCellRenderer(j, i);
comp = r.getTableCellRendererComponent(table,
model.getValueAt(j, i),
false, false, j, i);
cellWidth = comp.getPreferredSize().width;
if (cellWidth >= maxCellWidth) {
maxCellWidth = cellWidth;
}
}
column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
+ 10);
}
}
示例9: doExport
import javax.swing.table.TableModel; //导入依赖的package包/类
private void doExport(TableModel model, String title, Writer writer,
TracerProgressObject progress) throws IOException {
progress.setText("Initializing export...");
writeHeader(model, title, writer, progress);
if (progress.isFinished()) return;
progress.addStep("Exporting data...");
writeData(model, title, writer, progress);
if (progress.isFinished()) return;
progress.setText("Finishing export...");
writeFooter(model, title, writer, progress);
if (progress.isFinished()) return;
progress.setText("Data exported");
progress.finish();
}
示例10: actionPerformed
import javax.swing.table.TableModel; //导入依赖的package包/类
/**
* Invoked when an action occurs.
*/
public void actionPerformed(final ActionEvent e) {
List<JavaPlatform> platforms = JavaPlatform.getPlatforms();
String[] columnNames = new String[] { Bundle.LBL_JavaPlatform(),
Bundle.LBL_LastCalibrated() };
Object[][] columnData = new Object[platforms.size()][2];
for (int i = 0; i < platforms.size(); i++)
columnData[i] = new Object[] { platforms.get(i), null };
final TableModel model = new DefaultTableModel(columnData, columnNames) {
public boolean isCellEditable(int row, int column) { return false; }
};
SwingUtilities.invokeLater(new Runnable() {
public void run() { displayUI(model); }
});
RequestProcessor.getDefault().post(new Runnable() {
public void run() { refreshTimes(model); }
});
}
示例11: okButtonActionPerformed
import javax.swing.table.TableModel; //导入依赖的package包/类
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
// Update new enabled/disabled status for the Detectors
int num = factoryList.size();
DefaultSortedTableModel sorter = (DefaultSortedTableModel) detectorTable.getModel();
TableModel model = sorter.getBaseTableModel();
for (int i = 0; i < num; ++i) {
DetectorFactory factory = factoryList.get(i);
Boolean enabled = (Boolean) model.getValueAt(i, ENABLED_COLUMN);
factory.setEnabled(enabled.booleanValue());
}
closeDialog();
}
示例12: createModel
import javax.swing.table.TableModel; //导入依赖的package包/类
private static TableModel createModel(final Map<String,String> callbacks) {
final Object[][] data = new Object[callbacks.size()][];
final Iterator<Map.Entry<String,String>> it = callbacks.entrySet().iterator();
for (int i=0; it.hasNext(); i++) {
final Map.Entry<String,String> entry = it.next();
data[i] = new Object[] {entry.getKey(),entry.getValue()};
}
return new DefaultTableModel(
data,
new String[] {
NbBundle.getMessage(JFXDownloadModePanel.class, "JFXJavaScriptCallbacksPanel.tableCallbacks.columnModel.title0"), //NOI18N
NbBundle.getMessage(JFXDownloadModePanel.class, "JFXJavaScriptCallbacksPanel.tableCallbacks.columnModel.title1") //NOI18N
}) {
@Override
public boolean isCellEditable(int row, int column) {
return column != 0;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return String.class;
case 1:
return String.class;
default:
throw new IllegalStateException();
}
}
};
}
示例13: selectWithSpecialCharsIHeader
import javax.swing.table.TableModel; //导入依赖的package包/类
public void selectWithSpecialCharsIHeader() throws Throwable {
final JTable table = (JTable) ComponentUtils.findComponent(JTable.class, frame);
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
JTableHeader tableHeader = table.getTableHeader();
String[] columnNames = new String[table.getColumnCount()];
for (int i = 0; i < table.getColumnCount(); i++) {
columnNames[i] = table.getColumnName(i);
}
columnNames[3] = " # of \\Years[0,20]";
TableModel model = table.getModel();
try {
Field field = model.getClass().getDeclaredField("columnNames");
field.setAccessible(true);
field.set(model, columnNames);
} catch (Exception e) {
e.printStackTrace();
}
table.setModel(model);
tableHeader.getColumnModel().getColumn(3).setHeaderValue(" # of \\Years[0,20]");
table.invalidate();
table.setRowSelectionAllowed(true);
table.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.addRowSelectionInterval(1, 1);
table.addRowSelectionInterval(3, 3);
table.addColumnSelectionInterval(3, 3);
table.addColumnSelectionInterval(2, 2);
RTable rTable = new RTable(table, null, null, lr);
rTable.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("rows:[1,3],columns:[Sport, ## of \\Years[0#;20]]", call.getState());
}
示例14: store
import javax.swing.table.TableModel; //导入依赖的package包/类
@Override
public void store() {
Properties p = Properties.getDefault().getProperties("debugger.options.JPDA");
p.setBoolean("UseStepFilters", useStepFiltersCheckBox.isSelected());
p.setBoolean("FilterSyntheticMethods", filterSyntheticCheckBox.isSelected());
p.setBoolean("FilterStaticInitializers", filterStaticInitCheckBox.isSelected());
p.setBoolean("FilterConstructors", filterConstructorsCheckBox.isSelected());
TableModel filterClassesModel = filterClassesTable.getModel();
Set<String> allFilters = new LinkedHashSet<String>();
Set<String> enabledFilters = new HashSet<String>();
int n = filterClassesModel.getRowCount();
for (int i = 0; i < n; i++) {
boolean isEnabled = (Boolean) filterClassesModel.getValueAt(i, 0);
String clazz = (String) filterClassesModel.getValueAt(i, 1);
allFilters.add(clazz);
if (isEnabled) {
enabledFilters.add(clazz);
}
}
Properties.getDefault ().getProperties ("debugger").
getProperties ("sources").getProperties ("class_filters").
setCollection (
"all",
allFilters
);
Properties.getDefault ().getProperties ("debugger").
getProperties ("sources").getProperties ("class_filters").
setCollection (
"enabled",
enabledFilters
);
p.setBoolean("StepThroughFilters", stepThroughFiltersCheckBox.isSelected());
}
示例15: store
import javax.swing.table.TableModel; //导入依赖的package包/类
public void store(VariablesFormatter f) {
f.setName(nameTextField.getText());
f.setClassTypes(classTypesTextField.getText());
f.setIncludeSubTypes(subtypesCheckBox.isSelected());
f.setValueFormatCode(valueFormatCheckBox.isSelected() ? valueEditorPane.getText() : "");
f.setChildrenFormatCode(childrenCodeEditorPane.getText());
TableModel tableModel = childrenVariablesTable.getModel();
f.getChildrenVariables().clear();
for (int i = 0; i < tableModel.getRowCount(); i++) {
f.addChildrenVariable((String) tableModel.getValueAt(i, 0), (String) tableModel.getValueAt(i, 1));
}
f.setUseChildrenVariables(childrenVariablesRadioButton.isSelected());
f.setChildrenExpandTestCode(testChildrenCheckBox.isSelected() ? testChildrenEditorPane.getText() : "");
}