import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import com.zfqjava.swing.*; import com.zfqjava.swing.cell.*; public class SelectionModeDemo extends JDataGridBean { public SelectionModeDemo() { super(); configure(); } private void configure() { final JDataGrid dataGrid = getDataGrid(); String[] a_items = {"Multiple Interval", " Single Interval", "Single Selection"}; final JComboBox a = new JComboBox(a_items); a.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = a.getSelectedIndex(); if(index == 2) { dataGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if(index == 1) { dataGrid.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else if(index == 0) { dataGrid.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } } }); String[] b_items = {"Cell Selection", "Row Selection", "Column Selection" }; final JComboBox b = new JComboBox(b_items); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = b.getSelectedIndex(); if(index == 0) { dataGrid.setCellSelectionEnabled(true); } else if(index == 1) { dataGrid.setCellSelectionEnabled(false); dataGrid.setRowSelectionAllowed(true); } else if(index == 2) { dataGrid.setCellSelectionEnabled(false); dataGrid.setColumnSelectionAllowed(true); } } }); getToolBar(JDataGridBean.MAIN_TOOLBAR).add(b); getToolBar(JDataGridBean.MAIN_TOOLBAR).add(a); } public static void main(String[] args) { final SelectionModeDemo demo = new SelectionModeDemo(); demo.setDefaultCloseOperation(JBean.EXIT_ON_CLOSE); SwingUtilities.invokeLater(new Runnable() { public void run() { demo.showFrame(); demo.getDataGrid().requestFocus(); } }); } }