Make JTable multiple tow Selectable in Java

Description

The following code shows how to make JTable multiple tow Selectable.

Example


/*from   w w  w. java2  s.  com*/


 
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

public class Main {

  String[] headings = { "Name", "Customer ID", "Order #", "Status" };

  Object[][] data = {
    { "A", new Integer(3), "0", new Date() },
    { "B", new Integer(6), "4", new Date() },
    { "C", new Integer(9), "9", new Date() },
    { "D", new Integer(7), "1", new Date() },
    { "E", new Integer(4), "1", new Date() },
    { "F", new Integer(8), "2", new Date() },
    { "G", new Integer(6), "1", new Date() }
  };

  JTable jtabOrders = new JTable(data, headings);

  Main() {
    JFrame jfrm = new JFrame("JTable Demo");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(460, 180);
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JScrollPane jscrlp = new JScrollPane(jtabOrders);
    jtabOrders.setPreferredScrollableViewportSize(new Dimension(420, 60));

    jtabOrders.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jfrm.setVisible(true);
  
    jtabOrders.setColumnSelectionAllowed(false);
    jtabOrders.setRowSelectionAllowed(true);
  }

  public static void main(String args[]) {
     new Main();
  }
}




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer