本文整理匯總了Java中javax.swing.JTable.setSelectionModel方法的典型用法代碼示例。如果您正苦於以下問題:Java JTable.setSelectionModel方法的具體用法?Java JTable.setSelectionModel怎麽用?Java JTable.setSelectionModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.setSelectionModel方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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));
}