本文整理汇总了Java中javax.swing.JTable.setModel方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.setModel方法的具体用法?Java JTable.setModel怎么用?Java JTable.setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populatetable
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Loads the Data Array into the tmodel
*
* @param table to be populated
* @param header column header
* @param rows nullRoww data
* @return populated tmodel
*/
public static JTable populatetable(JTable table, String[] header, List<String[]> rows) {
removeRowSelection(table);
DefaultTableModel tablemodel = (DefaultTableModel) table.getModel();
tablemodel.setRowCount(0);
for (String col : header) {
tablemodel.addColumn(col);
}
for (String[] row : rows) {
tablemodel.addRow(row);
}
table.setModel(tablemodel);
return table;
}
示例2: construtorPanelIndicador
import javax.swing.JTable; //导入方法依赖的package包/类
private void construtorPanelIndicador(){
Object[] colunas = new String[]{"Pesquisa","Resultado"};
Object[][] dados = new Object[][]{
};
model = new DefaultTableModel(dados , colunas ){
public boolean isCellEditable(int row, int col){
return false;
}
};
tabela = new JTable();
tabela.setModel(model);
tabela.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
painelTabela = new JScrollPane();
painelTabela.setViewportView(tabela);
// busca e inserção dos resultados na tabela
this.consultaIndicadores();
}
示例3: CourseListPanel
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Create the panel.
*/
public CourseListPanel(String user,ProfessorFrame pf) throws Exception{
setLayout(new BorderLayout(0, 0));
TableCellRenderer buttonRenderer = new ButtonRenderer();
dao = new ProfessorDAO();
model=new tableModelTeach(dao.getAllCourses(user),user,pf);
table = new JTable();
table.setRowHeight(30);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultRenderer(JButton.class,buttonRenderer);
table.addMouseListener(new JTableButtonMouseListener(table));
table.setModel(model);
JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//resizeColumnWidth(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel tcm = table.getColumnModel();
tcm.getColumn(0).setPreferredWidth(800);
tcm.getColumn(1).setPreferredWidth(200);
scrollPane.setBounds(10, 57, 1320, 450);
add(scrollPane, BorderLayout.CENTER);
}
示例4: deletecol
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Delete a single column from the table model
*
* @param table target table
* @param col target column
* @deprecated
*/
static void deletecol(JTable table, int col) {
DefaultTableModel tmodel = (DefaultTableModel) table.getModel();
DefaultTableModel tmodel1 = new DefaultTableModel();
TableModelListener[] listeners = tmodel.getTableModelListeners();
Vector<?> v = tmodel.getDataVector();
Vector<?> v1 = newvector(v, col);
tmodel1.setDataVector(v1, getColumnIdentifiersremovecol(table, col));
table.setModel(tmodel1);
for (TableModelListener l : listeners) {
tmodel1.addTableModelListener(l);
}
}
示例5: addcol
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Adding column is done by creating new model by modifying older one.<p>
*
* Insert new column if column is outside the <code>limit</code> Adds new
* column if selected column inside the <code>limit</code>[email protected] _table
* target table
*
* @param limit the range to avoid inserting
*/
static void addcol(JTable table, int limit) {
try {
int sc = table.getSelectedColumn();
if (sc < limit - 1) {
sc = table.getColumnCount() - 1;
}
DefaultTableModel tableM = (DefaultTableModel) table.getModel();
DefaultTableModel tableM1 = new DefaultTableModel();
TableModelListener[] listeners = tableM.getTableModelListeners();
tableM1.setDataVector(newvectoraddcol(tableM.getDataVector(), sc), getColumnIdentifiersaddcol(sc + 1, table));
table.setModel(tableM1);
for (TableModelListener l : listeners) {
tableM1.addTableModelListener(l);
}
} catch (Exception ex) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例6: construtorTabelaModel
import javax.swing.JTable; //导入方法依赖的package包/类
private void construtorTabelaModel(){
Object[] colunas = new String[]{"Numero","Date Emissão","CNPJ/CPF","Razão Social/Nome","Quantidade de Itens","Valor Total"};
Object[][] dados = new Object[][]{
// {"100", "2017-06-13", "10388767618", "Matheus", "100", "1000.00"},
// {"200", "2017-06-13", "10388767618", "Matheus", "100", "1000.00"},
// {"300", "2017-06-13", "10388767618", "Matheus", "100", "1000.00"},
// {"400", "2017-06-13", "10388767618", "Matheus", "100", "1000.00"},
// {"500", "2017-06-13", "10388767618", "Matheus", "100", "1000.00"}
};
model = new DefaultTableModel(dados , colunas ){
public boolean isCellEditable(int row, int col){
return false;
}
};
tabela = new JTable();
tabela.setModel(model);
tabela.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
painelTabela = new JScrollPane();
painelTabela.setViewportView(tabela);
// busca e inserção de notas fiscais do banco na tabela
this.buscaNf();
}
示例7: erzeugeKundenTable
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Erzeugt die Tabelle für die Anzeige der Kunden.
*/
private void erzeugeKundenTable()
{
JScrollPane kundenAuflisterScrollPane = new JScrollPane();
kundenAuflisterScrollPane.setBorder(BorderFactory.createTitledBorder(
null, "Kunden", TitledBorder.LEADING,
TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT));
kundenAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
kundenAuflisterScrollPane.getVerticalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
kundenAuflisterScrollPane.getHorizontalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
_kundenTableModel = new KundenTableModel();
_kundenTable = new JTable();
kundenAuflisterScrollPane.setViewportView(_kundenTable);
_kundenTable.setModel(_kundenTableModel);
_kundenTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JTableHeader tableHeader = _kundenTable.getTableHeader();
tableHeader.setFont(UIConstants.HEADER_FONT);
tableHeader.setReorderingAllowed(false);
tableHeader.setResizingAllowed(false);
_kundenTable.setFont(UIConstants.TEXT_FONT);
_hauptPanel.add(kundenAuflisterScrollPane, BorderLayout.CENTER);
}
示例8: 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);
_medienTableModel = new VormerkMedienTableModel();
_medienTable = new JTable();
medienAuflisterScrollPane.setViewportView(_medienTable);
_medienTable.setModel(_medienTableModel);
JTableHeader tableHeader = _medienTable.getTableHeader();
tableHeader.setFont(UIConstants.HEADER_FONT);
tableHeader.setReorderingAllowed(false);
tableHeader.setResizingAllowed(false);
_medienTable.setFont(UIConstants.TEXT_FONT);
_hauptPanel.add(medienAuflisterScrollPane, BorderLayout.CENTER);
}
示例9: erzeugeVerleihkartenauflister
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Erzeuge das Tabellen-Panel, in dem die Verleihkarten angezeigt werden.
*/
private void erzeugeVerleihkartenauflister()
{
JPanel verleihkartenAuflisterPanel = new JPanel();
_hauptPanel.add(verleihkartenAuflisterPanel, BorderLayout.CENTER);
verleihkartenAuflisterPanel.setLayout(new BorderLayout());
verleihkartenAuflisterPanel
.setPreferredSize(new java.awt.Dimension(-1, -1));
verleihkartenAuflisterPanel.setSize(-1, -1);
verleihkartenAuflisterPanel.setBackground(UIConstants.BACKGROUND_COLOR);
JScrollPane verleihkartenAuflisterScrollPane = new JScrollPane();
verleihkartenAuflisterPanel.add(verleihkartenAuflisterScrollPane,
BorderLayout.CENTER);
verleihkartenAuflisterScrollPane
.setPreferredSize(new java.awt.Dimension(-1, -1));
verleihkartenAuflisterScrollPane.setSize(-1, -1);
verleihkartenAuflisterScrollPane.setBorder(BorderFactory
.createTitledBorder(null, "Verleihkarten", TitledBorder.LEADING,
TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT));
verleihkartenAuflisterScrollPane
.setBackground(UIConstants.BACKGROUND_COLOR);
verleihkartenAuflisterScrollPane.getVerticalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
verleihkartenAuflisterScrollPane.getHorizontalScrollBar()
.setBackground(UIConstants.BACKGROUND_COLOR);
_verleihkartenAuflisterTableModel = new VerleihkartenTableModel();
_verleihkartenAuflisterTable = new JTable();
verleihkartenAuflisterScrollPane
.setViewportView(_verleihkartenAuflisterTable);
_verleihkartenAuflisterTable
.setModel(_verleihkartenAuflisterTableModel);
JTableHeader tableHeader = _verleihkartenAuflisterTable
.getTableHeader();
tableHeader.setFont(UIConstants.HEADER_FONT);
tableHeader.setReorderingAllowed(false);
tableHeader.setResizingAllowed(false);
_verleihkartenAuflisterTable.setFont(UIConstants.TEXT_FONT);
}
示例10: iniciaJTable
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Método responsável por inicializar JTable
*
*/
private void iniciaJTable() {
tableTransacoes = new JTable();
tableTransacoes.setModel(new DefaultTableModel(new Object[][] {},
retornaNomeColunas()));
tableTransacoes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableTransacoes.setBounds(703, 24, -690, 140);
tableTransacoes.getTableHeader().setReorderingAllowed(false);
panelTransacoes.setLayout(null);
JScrollPane scrollPane = new JScrollPane(tableTransacoes);
scrollPane.setViewportView(tableTransacoes);
scrollPane.setBounds(10, 21, 691, 154);
panelTransacoes.add(scrollPane);
}
示例11: LoadData
import javax.swing.JTable; //导入方法依赖的package包/类
public static void LoadData (String sql,JTable tb) {
try{
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
tb.setModel((DbUtils.resultSetToTableModel(rs)));
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e ,"Thông báo lỗi",1);
}
}
示例12: createMapping
import javax.swing.JTable; //导入方法依赖的package包/类
private JComponent createMapping()
{
attributeModel = new AttributeTableModel();
attributeTable = new JTable(attributeModel);
attributeTable.setModel(attributeModel);
attributeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
attributeTable.changeSelection(0, 0, false, true);
return new JScrollPane(attributeTable);
}
示例13: PhotoList
import javax.swing.JTable; //导入方法依赖的package包/类
public PhotoList(ZooracleContentPanel zooracleContentPanel)
{
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.zooracleContentPanel = zooracleContentPanel;
// Set the frame characteristics
// setSize(150, 600);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
this.add(topPanel);
// Create some data
// String dataValues[][] = { { "12", "234", "67" }, { "-123", "43", "853" }, { "93", "89.2", "109" }, { "279", "9033", "3092" } };
// Create a new table instance
table = new JTable(null, columnNames);
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// table.setMinimumSize(new Dimension(150, 600));
// table.setPreferredSize(new Dimension(150, 600));
// table.setD
selectionModel = new DefaultListSelectionModel();
model = new DefaultTableModel();
// table.setC
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int selectionIndex = table.getSelectedRow();
if (lastSelectionIndex != selectionIndex)
{
lastSelectionIndex = selectionIndex;
if (selectionIndex==-1)
return;
System.out.println(table.getValueAt(selectionIndex, 0));
System.out.println("sele:" + selectionIndex);
if (PhotoList.this.zooracleContentPanel instanceof ImportView)
{
((ImportView)(PhotoList.this.zooracleContentPanel)).setCurrentPhoto(selectionIndex);
}
// if (selectionIndex > 2)
// PhotoList.this.maximize(false);
}
}
});
// table.setDefaultRenderer(Object.class, new EditedCellRenderer(this));
table.setSelectionModel(selectionModel);
table.setDefaultRenderer(String.class, new BoardTableCellRenderer());
table.setDefaultRenderer(Object.class, new BoardTableCellRenderer());
table.setModel(model);
// table.setMaximumSize(new Dimension(100, 300));
// Add the table to a scrolling pane
scrollPane = new JScrollPane();
// scrollPane.add(table.getTableHeader());
// scrollPane.add(table);
// topPanel.add(scrollPane);
topPanel.add(table.getTableHeader());
topPanel.add(new JScrollPane(table));
}
示例14: 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);
}
示例15: connectClassNames
import javax.swing.JTable; //导入方法依赖的package包/类
public static void connectClassNames(JTable table, SelectedTables selectedTables) {
table.setModel(new TableClassNamesModel(selectedTables));
setRenderer(table.getColumnModel().getColumn(0));
setRenderer(table.getColumnModel().getColumn(1));
}