本文整理了Java中javax.swing.table.TableModel
类的一些代码示例,展示了TableModel
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TableModel
类的具体详情如下:
包路径:javax.swing.table.TableModel
类名称:TableModel
暂无
代码示例来源:origin: igniterealtime/Smack
@Override
public void valueChanged(ListSelectionEvent e) {
if (table.getSelectedRow() == -1) {
// Clear the messageTextArea since there is none packet selected
messageTextArea.setText(null);
}
else {
// Set the detail of the packet in the messageTextArea
messageTextArea.setText(
(String) table.getModel().getValueAt(table.getSelectedRow(), 0));
// Scroll up to the top
messageTextArea.setCaretPosition(0);
}
}
}
代码示例来源:origin: log4j/log4j
protected static boolean contains(int row, TableModel model) {
if (model == null) {
return false;
}
if (row < 0) {
return false;
}
if (row >= model.getRowCount()) {
return false;
}
return true;
}
代码示例来源:origin: libgdx/libgdx
table.getColumnModel().getColumn(0).setPreferredWidth(10);
table.getColumnModel().getColumn(1).setPreferredWidth(50);
table.getColumnModel().getColumn(2).setPreferredWidth(100);
table.getColumnModel().getColumn(3).setPreferredWidth(20);
table.getColumnModel().getColumn(4).setPreferredWidth(30);
table.getTableHeader().setReorderingAllowed(false);
table.getModel().addTableModelListener(this);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked (MouseEvent e) {
scrollPane = new JScrollPane(table);
代码示例来源:origin: groovy/groovy-core
public Object next() {
int cols = self.getColumnCount();
Object[] rowData = new Object[cols];
for (int col = 0; col < cols; col++) {
rowData[col] = self.getValueAt(row, col);
}
row++;
return rowData;
}
代码示例来源:origin: groovy/groovy-core
public void propertyChange(PropertyChangeEvent event) {
update();
((TableModel) event.getOldValue()).removeTableModelListener(this);
((TableModel) event.getNewValue()).addTableModelListener(this);
}
}
代码示例来源:origin: groovy/groovy-core
public int compareRowsByColumn(int row1, int row2, int column) {
Class type = model.getColumnClass(column);
TableModel data = model;
Object o1 = data.getValueAt(row1, column);
Object o2 = data.getValueAt(row2, column);
代码示例来源:origin: stackoverflow.com
private JFrame frame = new JFrame("Frame");
private JPanel fatherCenter = new JPanel();
private JScrollPane tableScroll = new JScrollPane();
private myTableModel tableModel;
private JTable dialogTable;
Component comp = super.prepareRenderer(renderer, row, column);
if (!isRowSelected(row)) {
int modelRow = convertRowIndexToModel(row);
boolean type = (Boolean) getModel().getValueAt(modelRow, 2);
boolean type1 = (Boolean) getModel().getValueAt(modelRow, 3);
boolean type2 = (Boolean) getModel().isCellEditable(row, column);
comp.setForeground(Color.black);
if ((type) && (!type1)) {
tableScroll = new JScrollPane(dialogTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableScroll.setBorder(null);
fatherCenter.setLayout(new BorderLayout(10, 10));
fatherCenter.add(tableScroll, BorderLayout.CENTER);
pane.add(fatherCenter);
代码示例来源:origin: stackoverflow.com
private JTable table = new JTable(model);
});
this.table = table;
this.tableModel = table.getModel();
if (tableModel.getColumnClass(targetColumn) != Boolean.class) {
throw new IllegalArgumentException("Boolean column required.");
this.addItemListener(new ItemHandler());
header.addMouseListener(new MouseHandler());
tableModel.addTableModelListener(new ModelHandler());
boolean allTrue = true;
boolean allFalse = true;
for (int r = 0; r < tableModel.getRowCount(); r++) {
boolean b = (Boolean) tableModel.getValueAt(r, targetColumn);
allTrue &= b;
allFalse &= !b;
代码示例来源:origin: org.codehaus.izpack/izpack-installer
public void mouseClicked(MouseEvent e)
{
int selectedrow = conditiontable.getSelectedRow();
String selectedcondition = (String) conditiontable.getModel().getValueAt(selectedrow, 0);
if (e.getClickCount() == 2)
{
ConditionHistory aConditionHistory = conditionhistory.get(selectedcondition);
JFrame variabledetails = new JFrame("Details");
JTextPane detailspane = new JTextPane();
detailspane.setContentType("text/html");
detailspane.setText(aConditionHistory.getConditionHistoryDetails());
detailspane.setEditable(false);
JScrollPane scroller = new JScrollPane(detailspane);
Container container = variabledetails.getContentPane();
container.setLayout(new BorderLayout());
container.add(scroller, BorderLayout.CENTER);
variabledetails.pack();
variabledetails.setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
model.addRow(new Object[]{"Paul Reed Smith","Standard 24", "USA", ""});
JTable table = new JTable(model);
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(!isSelected){
Color background = table.getModel().getValueAt(row, 3).equals("") ? Color.GREEN : table.getBackground();
setBackground(background);
} else {
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(table));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
JTable table = new JTable(model);
model);
sorter.setRowFilter(filter);
table.setRowSorter(sorter);
JScrollPane scrollPane = new JScrollPane(table);
JFrame frame = new JFrame("Filtering Table");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent e) {
for(int row = 0;row < table.getRowCount();row++) {
System.out.println(table.getModel().getValueAt(table.convertRowIndexToModel(row), 0));
frame.getContentPane().add(btnNewButton, BorderLayout.SOUTH);
frame.getContentPane().add(scrollPane);
frame.setSize(300, 200);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
String [][] data = new String[][]{{"Test11", "Test12", "Test13", "Test14"},
{"Test21", "Test22", "Test23", "Test24"},
{"Test31", "Test32", "Test33", "Test34"}};
String[] columnName = new String[] {"Column1", "Column2", "Column3", "Column3"};
private void createDataTable(String[][] data, String[] columnName){
JFrame frame = new JFrame();
JScrollPane scrollPane = new JScrollPane();
JTable table = new JTable(data, columnName);
scrollPane.setViewportView(table);
frame.add(scrollPane);
frame.setSize(800, 800);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public String[][] getTableData (JTable table) {
TableModel dtm = table.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
String[][] tableData = new String[nRow][nCol];
for (int i = 0 ; i < nRow ; i++)
for (int j = 0 ; j < nCol ; j++)
tableData[i][j] = dtm.getValueAt(i,j).toString();
return tableData;
}
代码示例来源:origin: stackoverflow.com
int modelColumn = table.convertColumnIndexToModel(column);
return (modelColumn == 3) ? false : true;
table = new JTable(model);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(table);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.add(scrollPane);
frame.pack();
frame.setLocation(150, 150);
frame.setVisible(true);
if (column == 1 || column == 2) {
TableModel model = table.getModel();
int quantity = ((Integer) model.getValueAt(row, 1)).intValue();
double price = ((Double) model.getValueAt(row, 2)).doubleValue();
Double value = new Double(quantity * price);
model.setValueAt(value, row, 3);
代码示例来源:origin: stackoverflow.com
private JScrollPane jsp = new JScrollPane(editor);
private JTable table;
private int row;
JTable table = new JTable(new String[][]{
{"1\n2\n3\n4\n5\n6\n7", "1\n2\n3\n4\n5\n6\n7", "1\n2\n3\n4\n5\n6\n7"},
{"1\n2\n3\n4\n5\n6\n7", "1\n2\n3\n4\n5\n6\n7", "1\n2\n3\n4\n5\n6\n7"}},
new String[]{"First Column", "Second Column", "Third Column"});
JTableMultiLineSupport mls = new JTableMultiLineSupport();
table.setDefaultEditor(Object.class, mls);
table.setDefaultRenderer(Object.class, mls);
table.setRowHeight(0, 30);
table.setRowHeight(1, 70);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JFrame frame = new JFrame("Test");
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
table.getModel().setValueAt(editor.getText(), row, col);
return true;
代码示例来源:origin: stackoverflow.com
private JFrame frame = new JFrame("EachRowRendererEditor");
private String[] columnNames = {"Type", "Value"};
private Object[][] data = {
public TableCellRenderer getCellRenderer(int row, int column) {
editingClass = null;
int modelColumn = convertColumnIndexToModel(column);
if (modelColumn == 1) {
Class rowClass = getModel().getValueAt(row, modelColumn).getClass();
return getDefaultRenderer(rowClass);
} else {
return super.getCellRenderer(row, column);
int modelColumn = convertColumnIndexToModel(column);
if (modelColumn == 1) {
editingClass = getModel().getValueAt(row, modelColumn).getClass();
return getDefaultEditor(editingClass);
} else {
table.setPreferredScrollableViewportSize(table.getPreferredSize());
scrollPane = new JScrollPane(table);
frame.add(scrollPane);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
jScrollPane1 = new javax.swing.JScrollPane();
RVDataTable = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
RVDataTable.setModel(wrap.getModel());
RVDataTable.getModel().addTableModelListener(this);
jScrollPane1.setViewportView(RVDataTable);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
);
pack();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel(new Object[][]{
{Boolean.FALSE, "Row 1"},
int column = e.getColumn();
TableModel model = (TableModel) e.getSource();
Object data = model.getValueAt(row, column);
if (data instanceof Boolean) {
System.out.println("Value changed in Row: " + row + " Column: " + column + " New Value = " + data);
JTable table = new JTable(model);
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: jfree/jfreechart
/**
* Creates a panel that contains a table based on the specified table model.
*
* @param model the table model to use when constructing the table.
*
* @return The panel.
*/
public static JPanel createTablePanel(TableModel model) {
JPanel panel = new JPanel(new BorderLayout());
JTable table = new JTable(model);
for (int columnIndex = 0; columnIndex < model.getColumnCount(); columnIndex++) {
TableColumn column = table.getColumnModel().getColumn(columnIndex);
Class c = model.getColumnClass(columnIndex);
if (c.equals(Number.class)) {
column.setCellRenderer(new NumberCellRenderer());
}
}
panel.add(new JScrollPane(table));
return panel;
}
代码示例来源:origin: stackoverflow.com
private static JTable t = new JTable(new String[][]{{"1,1", "1,2"}, {"2,1", "2,2"}},
new String[]{"1", "2"});
private static JLabel l = new JLabel("Your selction will appear here");
private static JFrame f = new JFrame("Table selection listener Ex.");
private static ListSelectionListener myListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int col = t.getColumnModel().getSelectionModel().getLeadSelectionIndex();
int row = t.getSelectionModel().getLeadSelectionIndex();
try {
l.setText(t.getModel().getValueAt(row, col).toString());
} catch (IndexOutOfBoundsException ignore) {
t.getSelectionModel().addListSelectionListener(myListener);
t.getColumnModel().getSelectionModel().addListSelectionListener(myListener);
f.getContentPane().add(t, BorderLayout.NORTH);
f.getContentPane().add(l, BorderLayout.CENTER);
f.pack();
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTable table = new JTable(tmodel);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
add(new JScrollPane(table), BorderLayout.CENTER);
JButton jb = new JButton("click me"); //button to display last cell data
jb.addActionListener(new ActionListener() {
JOptionPane.showMessageDialog(null, table.getModel().getValueAt(5, 0));
add(jb, BorderLayout.SOUTH);
pack();
setVisible(true);
内容来源于网络,如有侵权,请联系作者删除!