Package javax.swing

Examples of javax.swing.DefaultListSelectionModel$Segment


      if (e.isShiftDown() && SwingUtilities.isLeftMouseButton(e)) {
        int index = mSource.locationToIndex(e.getPoint());
        mSource.setSelectionInterval(index, mLastSelectedIndex);
      } else if (!e.isControlDown() && !e.isShiftDown()
          && SwingUtilities.isLeftMouseButton(e)) {
        DefaultListSelectionModel model = (DefaultListSelectionModel) mSource
            .getSelectionModel();
        int index = mSource.locationToIndex(e.getPoint());
        if (!model.isSelectedIndex(index)) {
          mSource.setSelectedIndex(index);
          mLastSelectedIndex = index;
        }
      }
    }
View Full Code Here


  public void mouseReleased(MouseEvent e) {
    int index = mSource.locationToIndex(e.getPoint());

    if (mSource.isEnabled()) {
      if (e.isControlDown() && SwingUtilities.isLeftMouseButton(e)) {
        DefaultListSelectionModel model = (DefaultListSelectionModel) mSource
            .getSelectionModel();

        if (model.isSelectedIndex(index)) {
          model.removeSelectionInterval(index, index);
        } else {
          model.addSelectionInterval(index, index);
        }

        mLastSelectedIndex = index;
      } else if (!e.isShiftDown() && !e.isControlDown()
          && SwingUtilities.isLeftMouseButton(e)) {
View Full Code Here

     * Needs to be called before displaying the DbfTableModel.
     */
    public JTable getTable() {

        if (table == null) {
            lsm = new DefaultListSelectionModel();
            table = new JTable();
            table.setModel(getModel());
            table.setSelectionModel(lsm);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

View Full Code Here

            panel.setBorder(BorderFactory.createEtchedBorder());
        }

        panel.setLayout(new BorderLayout());

        JScrollPane pane = new JScrollPane(getTable(new DefaultListSelectionModel()));
        panel.add(pane, BorderLayout.CENTER);

        controlPanel = new JPanel();
        panel.add(controlPanel, BorderLayout.SOUTH);
View Full Code Here

          }
          {
            topPanel.add(new JScrollPane(nameList = new JList()));
            nameList.setModel(new DefaultListModel());
          }
          DefaultListSelectionModel disableSelections = new DefaultListSelectionModel() {
            public void setSelectionInterval (int index0, int index1) {
            }
          };
          messageList.setSelectionModel(disableSelections);
          nameList.setSelectionModel(disableSelections);
View Full Code Here

          }
          {
            topPanel.add(new JScrollPane(nameList = new JList()));
            nameList.setModel(new DefaultListModel());
          }
          DefaultListSelectionModel disableSelections = new DefaultListSelectionModel() {
            public void setSelectionInterval (int index0, int index1) {
            }
          };
          messageList.setSelectionModel(disableSelections);
          nameList.setSelectionModel(disableSelections);
View Full Code Here

        EventSelectionModel<String> eventSelectionModel = new EventSelectionModel<String>(source);
        ListSelectionChangeCounter eventSelectionModelCounter = new ListSelectionChangeCounter();
        eventSelectionModel.addListSelectionListener(eventSelectionModelCounter);

        // create DefaultListSelectionModel (SUN's selection model)
        DefaultListSelectionModel defaultListSelectionModel = new DefaultListSelectionModel();
        ListSelectionChangeCounter defaultListSelectionModelCounter = new ListSelectionChangeCounter();
        defaultListSelectionModel.addListSelectionListener(defaultListSelectionModelCounter);

        // create two different JLists (one with EventSelectionModel and one with DefaultListSelectionModel) that share the same data model
        JList eventList = new JList(model);
        eventList.setSelectionModel(eventSelectionModel);

        JList defaultList = new JList(model);
        defaultList.setSelectionModel(defaultListSelectionModel);

        // select the first element in both selection models
        eventSelectionModel.setSelectionInterval(0, 0);
        defaultListSelectionModel.setSelectionInterval(0, 0);

        // verify that each selection model broadcasted the selection event
        assertEquals(1, defaultListSelectionModelCounter.getCountAndReset());
        assertEquals(1, eventSelectionModelCounter.getCountAndReset());

        // change an element in the model which is selected in the selection models
        source.set(0, "Bart");

        // selection should not have changed in either selection model
        assertEquals(0, defaultListSelectionModel.getMinSelectionIndex());
        assertEquals(0, defaultListSelectionModel.getMaxSelectionIndex());
        assertEquals(0, defaultListSelectionModel.getLeadSelectionIndex());
        assertEquals(0, defaultListSelectionModel.getAnchorSelectionIndex());

        assertEquals(0, eventSelectionModel.getMinSelectionIndex());
        assertEquals(0, eventSelectionModel.getMaxSelectionIndex());
        assertEquals(0, eventSelectionModel.getLeadSelectionIndex());
        assertEquals(0, eventSelectionModel.getAnchorSelectionIndex());
View Full Code Here

                                        }
                                        {
                                                topPanel.add(new JScrollPane(nameList = new JList()));
                                                nameList.setModel(new DefaultListModel());
                                        }
                                        DefaultListSelectionModel disableSelections = new DefaultListSelectionModel() {
                                                public void setSelectionInterval (int index0, int index1) {
                                                }
                                        };
                                        messageList.setSelectionModel(disableSelections);
                                        nameList.setSelectionModel(disableSelections);
View Full Code Here

}

  private void testMultipleIntervalSelection(TestHarness harness)
  {
    harness.checkPoint("MULTIPLE_INTERVAL_SELECTION");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    m.addSelectionInterval(3, 6);
    m.addListSelectionListener(this);
    m.setLeadSelectionIndex(1);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.isSelectedIndex(3), true);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(m.isSelectedIndex(5), false);
    harness.check(m.isSelectedIndex(6), false);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 1);
    harness.check(lastEvent.getLastIndex(), 6);
  }
View Full Code Here

public class isSelectedIndex implements Testlet
{
  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    harness.check(m.isSelectedIndex(99), false);
    m.addSelectionInterval(99, 99);
    harness.check(m.isSelectedIndex(99), true);
    m.clearSelection();
    harness.check(m.isSelectedIndex(99), false);
   
    // try a negative index
    harness.check(m.isSelectedIndex(-1), false);
    harness.check(m.isSelectedIndex(-2), false);
  }
View Full Code Here

TOP

Related Classes of javax.swing.DefaultListSelectionModel$Segment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.