本文整理汇总了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));
}