本文整理汇总了Java中javax.swing.JTable.getModel方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getModel方法的具体用法?Java JTable.getModel怎么用?Java JTable.getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel component = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
File file = (File)value;
String displayNameText = (file != null) ? displayName.getDisplayName(file) : null;
component.setText(displayNameText);
if (!(table.getModel() instanceof ConfigFileSelectionTableModel)) {
return component;
}
ConfigFileSelectionTableModel model = (ConfigFileSelectionTableModel)table.getModel();
String toolTipText = null;
if (!model.isEnabled(row)) {
toolTipText = NbBundle.getMessage(ConfigFilesUIs.class, "LBL_FileAlreadyAdded");
}
component.setToolTipText(toolTipText);
component.setEnabled(model.isEnabled(row));
return component;
}
示例2: autoSizeTableColumns
import javax.swing.JTable; //导入方法依赖的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);
}
}
示例3: createTransferable
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
protected Transferable createTransferable(JComponent source) {
JTable table = (JTable) source;
if (table.getModel() instanceof TestDataModel) {
TestDataModel tdm = (TestDataModel) table.getModel();
TestDataDetail td = new TestDataDetail();
td.setSheetName(tdm.getName());
for (int col : table.getSelectedColumns()) {
if (col > 3) {
td.getColumnNames().add(table.getColumnName(col));
}
}
return new TransferableNode(td, DataFlavors.TESTDATA_FLAVOR);
}
return null;
}
示例4: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent( JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int rowIndex,
int columnIndex )
{
MergeTableModel model = (MergeTableModel) table.getModel();
String leftProperty = propertyOn( model.leftLineAtRow(rowIndex) );
String rightProperty = propertyOn( model.rightLineAtRow(rowIndex) );
boolean same = leftProperty.equals( rightProperty );
Component c = super.getTableCellRendererComponent( table,
value,
isSelected,
hasFocus,
rowIndex,
columnIndex );
c.setForeground( same ? Color.BLACK : Color.RED );
return c;
}
示例5: UserTableHeaderCellRenderer
import javax.swing.JTable; //导入方法依赖的package包/类
public UserTableHeaderCellRenderer(JTable table) {
this.tableModel = (UserTableModel) table.getModel();
this.tableHeader = table.getTableHeader();
selectBox = new JCheckBox(tableModel.getColumnName(0));
selectBox.setSelected(false);
tableHeader.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 0) {
int selectColumn = tableHeader.columnAtPoint(e.getPoint());
if (selectColumn == 0) {
boolean value = !selectBox.isSelected();
selectBox.setSelected(value);
tableModel.selectAll(value);
tableHeader.repaint();
}
}
}
});
}
示例6: mouseClicked
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTableHeader header = (JTableHeader) e.getSource();
JTable table = header.getTable();
TableColumnModel columnModel = table.getColumnModel();
int vci = columnModel.getColumnIndexAtX(e.getX());
int mci = table.convertColumnIndexToModel(vci);
if (mci == targetColumnIndex) {
if (SwingUtilities.isLeftMouseButton(e)) {
TableColumn column = columnModel.getColumn(vci);
Object v = column.getHeaderValue();
boolean b = Status.DESELECTED.equals(v);
TableModel m = table.getModel();
for (int i = 0; i < m.getRowCount(); i++) {
m.setValueAt(b, i, mci);
}
column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
} else if (SwingUtilities.isRightMouseButton(e)) {
if (popupMenu != null) {
popupMenu.show(table, e.getX(), 0);
}
}
}
}
示例7: getTableCellEditorComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) {
oldValue = value;
int modelColumn = table.convertColumnIndexToModel(column);
TableModel tm = table.getModel();
dbColumn = null;
if (tm instanceof ResultSetTableModel) {
textField.setInputVerifier(verifier);
dbColumn = ((ResultSetTableModel) tm).getColumn(modelColumn);
} else {
textField.setInputVerifier(null);
}
Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column);
if (suppressEditorBorder && c instanceof JComponent) {
((JComponent) c).setBorder(BorderFactory.createEmptyBorder());
}
return c;
}
示例8: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}
// This doesn't work in the presence of table row sorting:
//boolean isTotalRow = row == table.getModel().getRowCount()-1;
FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
boolean isTotalRow = summary == ((CoverageTableModel)table.getModel()).total;
setEmphasize(isTotalRow);
setSelected(isSelected);
float coverage = (Float) value;
setCoveragePercentage(coverage);
//setStats(summary.getLineCount(), summary.getExecutedLineCount(),
// summary.getInferredCount(), summary.getPartialCount());
return this;
}
示例9: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
boolean joinTable = false;
boolean validClass = true;
boolean existentUpdate = false;
String problemDisplayName = null;
if (jTable.getModel() instanceof TableClassNamesModel) {
TableClassNamesModel model = (TableClassNamesModel)jTable.getModel();
Table table = model.getTableAt(row);
joinTable = table.isJoin();
if (column == 1) {
existentUpdate = table.getDisabledReason() instanceof Table.ExistingDisabledReason;
validClass = model.isValidClass(table);
if (!validClass) {
problemDisplayName = model.getProblemDisplayName(table);
}
}
}
Object realValue = null;
if (joinTable && column == 1) {
realValue = NbBundle.getMessage(TableUISupport.class, "LBL_JoinTable");
} else {
realValue = value;
}
JComponent component = (JComponent)super.getTableCellRendererComponent(jTable, realValue, isSelected, hasFocus, row, column);
component.setEnabled(!joinTable && !existentUpdate);
component.setToolTipText(joinTable ? NbBundle.getMessage(TableUISupport.class, "LBL_JoinTableDescription") : problemDisplayName);
component.setForeground((validClass) ? nonErrorForeground : errorForeground);
return component;
}
示例10: loadFileinTable
import javax.swing.JTable; //导入方法依赖的package包/类
public static void loadFileinTable(File file, JTable table) {
if (file.exists()) {
try (Reader in = new FileReader(file)) {
CSVParser parser = CSVFormat.EXCEL.withHeader().withSkipHeaderRecord().withIgnoreEmptyLines().parse(in);
if (!parser.getHeaderMap().isEmpty()) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
for (String columnHeader : parser.getHeaderMap().keySet()) {
if (!columnHeader.trim().isEmpty()) {
model.addColumn(columnHeader);
}
}
List<CSVRecord> records = parser.getRecords();
for (CSVRecord record : records) {
Object[] row = new Object[record.size()];
for (int i = 0; i < record.size(); i++) {
row[i] = record.get(i);
}
model.addRow(row);
}
}
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
}
}
示例11: pasteFromClipboard
import javax.swing.JTable; //导入方法依赖的package包/类
public static void pasteFromClipboard(JTable table) {
int startRow = table.getSelectedRows()[0];
int startCol = table.getSelectedColumns()[0];
String pasteString;
try {
pasteString = (String) (CLIPBOARD.getContents(null).getTransferData(DataFlavor.stringFlavor));
} catch (Exception e) {
Logger.getLogger(XTableUtils.class.getName()).log(Level.WARNING, "Invalid Paste Type", e);
return;
}
if (table.getModel() instanceof UndoRedoModel) {
((UndoRedoModel) table.getModel()).startGroupEdit();
}
String[] lines = pasteString.split(LINE_BREAK);
for (int i = 0; i < lines.length; i++) {
String[] cells = lines[i].split(CELL_BREAK);
for (int j = 0; j < cells.length; j++) {
if (table.getRowCount() <= startRow + i) {
if (table.getModel() instanceof DataModel) {
if (!((DataModel) table.getModel()).addRow()) {
return;
}
}
}
if (table.getRowCount() > startRow + i && table.getColumnCount() > startCol + j) {
table.setValueAt(cells[j], startRow + i, startCol + j);
}
}
}
if (table.getModel() instanceof UndoRedoModel) {
((UndoRedoModel) table.getModel()).stopGroupEdit();
}
}
示例12: CountingTableModel
import javax.swing.JTable; //导入方法依赖的package包/类
public CountingTableModel(JTable table) {
this.backingTable = table;
this.backingSorter = this.backingTable.getRowSorter();
if(this.backingSorter != null) {
this.backingSorter.addRowSorterListener(this);
}
backingTable.addPropertyChangeListener(this);
this.backingTableModel = table.getModel();
this.backingTableModel.addTableModelListener(this);
setCount(backingTable.getRowCount());
}
示例13: setSelectedRow
import javax.swing.JTable; //导入方法依赖的package包/类
private void setSelectedRow(JTable table, Object selectedObject, int objectColumn) {
if(table==null || selectedObject==null || objectColumn==-1)return;
//after move to java6 as minimum requirent for nb may consider to replace with JTable::convertRowIndexToModel and back
//current mplementation works with java5
TableModel model = table.getModel();
int rowCount=table.getRowCount();
for(int i=0; i<rowCount; i++) {
if(selectedObject.equals(model.getValueAt(i, objectColumn))) {
table.setRowSelectionInterval(i, i);
table.scrollRectToVisible(table.getCellRect(i, objectColumn, true));
break;
}
}
}
示例14: printDebugData
import javax.swing.JTable; //导入方法依赖的package包/类
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i = 0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j = 0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
示例15: formatValue
import javax.swing.JTable; //导入方法依赖的package包/类
protected Object formatValue(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
DetailsTableModel model = (DetailsTableModel)table.getModel();
int columnIndex = table.convertColumnIndexToModel(column);
ValueItemDescriptor descriptor = model.getDescriptor(columnIndex);
String valueString = descriptor.getValueString((Long)value,
ItemValueFormatter.FORMAT_DETAILS);
// Improve spacing of the text
return " " + valueString + " "; // NOI18N
}