Example usage for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.

Prototype

int MULTIPLE_INTERVAL_SELECTION

To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.

Click Source Link

Document

A value for the selectionMode property: select one or more contiguous ranges of indices at a time.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);// w  w w .  j  a va2s.c o  m

    int row = 3;
    int col = 2;
    boolean toggle = true;
    boolean extend = false;
    table.changeSelection(row, col, toggle, extend);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);//from  w w w.ja  v  a  2 s .  c o  m

    int row = 5;
    int col = 3;
    boolean toggle = false;
    boolean extend = true;
    table.changeSelection(row, col, toggle, extend);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTable table = new JTable();

    if (table.getCellSelectionEnabled()) {
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        int rowIndexStart = table.getSelectedRow();
        int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex();
        int colIndexStart = table.getSelectedColumn();
        int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex();

    }/*from  w  w  w  .jav  a2 s . c  om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTable table = new JTable();

    if (table.getCellSelectionEnabled()) {
        // In the other modes, the set of selected cells can be retrieved using
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        // Get the min and max ranges of selected cells
        int rowIndexStart = table.getSelectedRow();
        int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex();
        int colIndexStart = table.getSelectedColumn();
        int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex();

        // Check each cell in the range
        for (int r = rowIndexStart; r <= rowIndexEnd; r++) {
            for (int c = colIndexStart; c <= colIndexEnd; c++) {
                if (table.isCellSelected(r, c)) {
                    System.out.println("cell is selected");
                }/*from w ww  . ja  va 2  s  . com*/
            }
        }
    }
}

From source file:SelectionModeDemo.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(100);// ww  w.  ja va 2 s.c o  m
    for (int i = 0; i < 100; i++) {
        model.addElement(Integer.toString(i));
    }
    JList jlist2 = new JList(model);
    jlist2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

    frame.setSize(300, 350);
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());

    list = new JList(label);
    JScrollPane pane = new JScrollPane(list);

    DefaultListSelectionModel m = new DefaultListSelectionModel();

    m.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            System.out.println(e.toString());
        }/*from ww  w .  j  ava2s  .c  o m*/
    });

    list.setSelectionModel(m);

    System.out.println(m.getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

Main() {
    JFrame jfrm = new JFrame("JTable Demo");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(460, 180);/*from  w w  w.j  a v a2  s.  com*/
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JScrollPane jscrlp = new JScrollPane(jtabOrders);
    jtabOrders.setPreferredScrollableViewportSize(new Dimension(420, 60));

    jtabOrders.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtabOrders.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jfrm.setVisible(true);

    jtabOrders.setCellSelectionEnabled(true);
}

From source file:com.emr.schemas.SchemerMapper.java

/**
 * Constructor/*from  w  ww  . j  a  v a 2s  .c o  m*/
 * @param emrConn {@link Connection} Connection to the EMR database
 * @param emrDbName {@link String} Database name
 */
public SchemerMapper(Connection emrConn, String emrDbName) {
    this.emrConn = emrConn;
    this.emrDbName = emrDbName;
    listModel = new DefaultListModel<String>();
    initComponents();
    this.setClosable(true);

    SourceTablesListener listSelectionListener = new SourceTablesListener(txtSelectedTables, listOfTables);

    sourceTablesList.setCellRenderer(new CheckboxListCellRenderer());
    sourceTablesList.addListSelectionListener(listSelectionListener);
    sourceTablesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    sourceTablesList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
    //getDatabaseMetaData();
    final ListUpdater lu = new ListUpdater();
    lu.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            switch (event.getPropertyName()) {
            case "progress":
                System.out.println("Fetching data from db");
                break;
            case "state":
                switch ((SwingWorker.StateValue) event.getNewValue()) {
                case DONE:
                    try {
                        listModel = lu.get();
                        sourceTablesList.setModel(listModel);
                    } catch (final CancellationException ex) {
                        Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ExecutionException ex) {
                        Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    break;
                }
                break;
            }
        }

    });
    lu.execute();

}

From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.WorkItemsTableModel.java

public WorkItemsTableModel(final Column[] columns) {
    assert columns != null;
    this.columns = columns.clone();
    selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}

From source file:com.intuit.tank.tools.debugger.SelectDialog.java

/**
 * @param arg0//from w ww.  j  ava  2 s .c o m
 */
public SelectDialog(Frame f, List<SELECTION_TYPE> items, String itemType, boolean singleSelection) {
    super(f, true);
    setLayout(new BorderLayout());
    this.items = items;
    filterField = new JTextField();
    filterField.addKeyListener(new KeyHandler());
    list = new JList(items.toArray());
    list.setSelectionMode(singleSelection ? ListSelectionModel.SINGLE_SELECTION
            : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            okBT.setEnabled(list.getSelectedIndex() != -1);
        }
    });
    list.addMouseListener(new MouseAdapter() {

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                select();
            }
        }

    });
    JPanel labelPanel = new JPanel(new GridLayout(singleSelection ? 1 : 2, 1, 0, 5));
    labelPanel.add(new JLabel("Select a " + itemType + "."));
    if (!singleSelection) {
        String key = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "" : "control";
        System.out.println(key);
        labelPanel.add(new JLabel("Hold down the " + key + " key to select multiple " + itemType + "."));
    }
    add(labelPanel, BorderLayout.NORTH);
    JScrollPane sp = new JScrollPane(list);
    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(filterField, BorderLayout.NORTH);
    centerPanel.add(sp, BorderLayout.CENTER);
    add(centerPanel, BorderLayout.CENTER);
    add(createButtonPanel(), BorderLayout.SOUTH);
    setSize(new Dimension(400, 500));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    WindowUtil.centerOnParent(this);
}