本文整理汇总了Java中javax.swing.JTable.getColumnName方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getColumnName方法的具体用法?Java JTable.getColumnName怎么用?Java JTable.getColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getColumnName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setJTableOptions
import javax.swing.JTable; //导入方法依赖的package包/类
public static void setJTableOptions(final String name, final JTable table,
final Properties properties) {
setInteger(name + "_col_count", table.getColumnCount(), properties);
final String cNames[] = new String[table.getColumnCount()];
for (int i = 0; i < cNames.length; i++)
cNames[i] = table.getColumnName(i);
for (final String element : cNames) {
try {
setInteger(name + "_col_" + element + "_width", table
.getColumn(element).getWidth(), properties);
setInteger(name + "_col_" + element + "_index",
table.convertColumnIndexToView(table.getColumn(element)
.getModelIndex()), properties);
} catch (final Exception e) {
}
}
}
示例2: getTableCellEditorComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, final int column) {
final JComponent c = (JComponent) super.getTableCellEditorComponent(table, value, isSelected, row, column);
this.tableModel = table.getModel();
this.columnName = table.getColumnName(column);
this.modelRow = table.convertRowIndexToModel(row);
this.modelColumn = table.convertColumnIndexToModel(column);
this.tc = c instanceof JTextComponent ? (JTextComponent) c : null;
JPanel panel = new JPanel(new BorderLayout()) {
@Override
public void addNotify() {
super.addNotify();
c.requestFocus();
}
};
panel.add(c);
if (suppressEditorBorder) {
c.setBorder(BorderFactory.createEmptyBorder());
}
panel.add(customEditorButton, BorderLayout.EAST);
panel.revalidate();
panel.repaint();
return panel;
}
示例3: getColumnName
import javax.swing.JTable; //导入方法依赖的package包/类
public String getColumnName(int c) {
JTable table = (JTable) component;
JTableHeader tableHeader = table.getTableHeader();
String columnName;
if (tableHeader != null) {
columnName = tableHeader.getColumnModel().getColumn(c).getHeaderValue().toString();
} else {
columnName = table.getColumnName(c);
}
return columnName;
}
示例4: getJTableOptions
import javax.swing.JTable; //导入方法依赖的package包/类
public static void getJTableOptions(final String name, final JTable table,
final Properties properties) {
final Integer colCount = getObjectInteger(name + "_col_count",
properties);
if (colCount == null || colCount.intValue() != table.getColumnCount())
return;
final String cNames[] = new String[table.getColumnCount()];
final Object cols[] = new Object[table.getColumnCount()];
for (int i = 0; i < cNames.length; i++) {
cNames[i] = table.getColumnName(i);
cols[i] = table.getColumnModel().getColumn(i);
}
for (final String element : cNames) {
final int width = getInteger(name + "_col_" + element + "_width",
table.getColumn(element).getWidth(), properties);
table.getColumn(element).setPreferredWidth(width);
}
final TableColumnModel cm = table.getColumnModel();
final int tci[] = new int[cNames.length];
for (int i = 0; i < cNames.length; i++)
cm.removeColumn((TableColumn) cols[i]);
for (int i = 0; i < cNames.length; i++) {
tci[i] = getInteger(name + "_col_" + cNames[i] + "_index", i,
properties);
}
for (int i = 0; i < cNames.length; i++)
for (int j = 0; j < cNames.length; j++)
if (tci[j] == i)
cm.addColumn((TableColumn) cols[j]);
}
示例5: erzeugeMedienTable
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Erzeugt die Tabelle für die Anzeige der Medien.
*/
private void erzeugeMedienTable()
{
JScrollPane medienAuflisterScrollPane = new JScrollPane();
medienAuflisterScrollPane.setBorder(BorderFactory.createTitledBorder(
null, "Medien", TitledBorder.LEADING,
TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT));
medienAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
medienAuflisterScrollPane.getVerticalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
medienAuflisterScrollPane.getHorizontalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
_ausleiheMedienTableModel = new AusleiheMedienTableModel();
_medienTable = new JTable();
medienAuflisterScrollPane.setViewportView(_medienTable);
_medienTable.setModel(_ausleiheMedienTableModel);
JTableHeader tableHeader = _medienTable.getTableHeader();
tableHeader.setFont(UIConstants.HEADER_FONT);
tableHeader.setReorderingAllowed(false);
tableHeader.setResizingAllowed(false);
_medienTable.setFont(UIConstants.TEXT_FONT);
// Text in der 3. Spalte mittig ausrichten
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
String columnName = _medienTable.getColumnName(2);
TableColumn column = _medienTable.getColumn(columnName);
column.setCellRenderer(renderer);
_hauptPanel.add(medienAuflisterScrollPane, BorderLayout.CENTER);
}
示例6: exportModelToCSV
import javax.swing.JTable; //导入方法依赖的package包/类
public static void exportModelToCSV(JTable table, File file, Boolean hflag) throws IOException {
removeEmptyRows(table);
cancelEditing(table);
ArrayList<String[]> data = new ArrayList<>();
ArrayList<Integer> expList = new ArrayList<>();
ArrayList<String> row = new ArrayList<>();
int colCount = table.getColumnModel().getColumnCount(),
rowCount = table.getModel().getRowCount(), i;
for (i = 0; i < colCount; i++) {
Object hval = table.getColumnName(i);
if (hval == null || "".equals(hval.toString())) {
expList.add(i);
} else {
row.add(hval.toString());
}
}
data.add(row.toArray(new String[row.size()]));
for (i = 0; i < rowCount; i++) {
row.clear();
for (int j = 0; j < colCount; j++) {
if (!expList.contains(j)) {
Object val = table.getModel().getValueAt(i, j);
row.add((val == null) ? "" : val.toString());
}
}
data.add(row.toArray(new String[row.size()]));
}
// try (CSVWriter<String[]> csvWriter = CSVWriterBuilder.newDefaultWriter(new FileWriter(file))) {
// csvWriter.writeAll(data);
// }
}