Modifying JList selection behavior

What I want to do is change the selection behavior so that if the user clicks on the left half of the cell, the item is selected, but if the user clicks on the right half, the item is not selected. I already have the code to determine where the user clicked, but can't get the selection to not occur when I determine that the user clicked in the "non-selection area" right half.

After overriding...
public void setSelectedIndices(int[] indices)
public void setSelectedValue(Object anObject, boolean shouldScroll)
public void setSelectionInterval(int anchor, int lead)
public void setSelectedIndex(int index)...it worked. I implemented each of these like this.
public void methodX()
  if( clickOnSelectableRegion )
    super.methodX();
  clickOnSelectableRegion = true;
}It is the responsibility of an outside MouseListener to determine if the click falls on a selectable region or not. If a click occurs that is not on a selectable region, the listener should call setOnSelectableRegion(false) on the List. I set the value back to true so the listener only has to notify the list of "ignorable" clicks.

Similar Messages

  • Overriding JList selection behavior

    Hi,
    I am trying to implement a multiple selection JList that when you right/left click on an item it selects the item, if it is not selected. Deselect the item if it is already selected. The right click works fine, but the left click still works as the default. My code is as follow:
    String[] items={ "item 0", "item 1", "item 2", "item 3" , "item 4" };
    final JList l = new JList(items);
    l.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    l.setUI(new BasicListUI(){
    protected MouseInputListener createMouseInputListener()
    return new BasicListUI.MouseInputHandler()
    {//react on mouse pressed
    public void mousePressed(MouseEvent e)
    int row = convertYToRow(e.getY() );
    if(row >= 0)
    {    l.setValueIsAdjusting(true);
    if(l.isSelectedIndex(row) )
    l.removeSelectionInterval(row,row);
    else l.addSelectionInterval(row,row);
    public void mouseRelease(MouseEvent e)
    l.setValueIsAdjusting(false);
    Thanks you.

    I'm doing something similar with an inner class of my JList subclass. This code enables toggling and drag-selecting with button 1, and selection clearing with button > 1. Here's the inner class:
    class EasySelectListUI extends BasicListUI {
    protected MouseInputListener createMouseInputListener() {
    return new BasicListUI.MouseInputHandler() {
    public void mousePressed(MouseEvent e) {
    // clear selection first if button > 1
    if (e.getButton() != 1)
    clearSelection();
    int row = convertYToRow(e.getY());
    if (row >= 0) {
    setValueIsAdjusting(true);
    if (isSelectedIndex(row))
    removeSelectionInterval(row, row);
    else
    addSelectionInterval(row, row);
    public void mouseDragged(MouseEvent e) {
    // drag select only for button 1
    if ((e.getModifiers()&MouseEvent.BUTTON1_MASK) ==0)
    return;
    int row = convertYToRow(e.getY());
    if (row >= 0) {
    setValueIsAdjusting(true);
    addSelectionInterval(row, row);
    public void mouseReleased(MouseEvent e) {
    setValueIsAdjusting(false);

  • "resolving alias to" message using aliases on 10.6.8 plus slow text-selection behavior

    Recently after no particular change to my Mac Pro3,2 running 10.6.8 other than some routine software updates, whenever I open an alias on my desktop to standard folders or files, a message shows up "Resolving alias to" whatever the alias name and there's a 2-3 second delay before the folder/file opens. I've found discussion of this issue in some archived discussions but never found a comfirmed solution described, so I'm raising this again. As in others' encounter with this behavior, the slow opening of aliases happens (1) only in my own user account, not in a guest account I set up for test purposes [I have no other user accounts than these], and (2) only happens the FIRST time I open an alias. Subsequent uses of the alias work normally.
    Another strange but possibly related behavior that began at the same time as this alias delay is harder to describe but involves a problem when selecting text using mouse clicks or even highlighting with the mouse for editing. For example, to edit the name of a file or folder on my desktop, I would normally click on the file/folder name, pause a moment and click again: this puts me in edit mode with the current file/folder name highlighted/selected. Now when I attempt this procedure, the second time I click immediately opens the file/folder, as though I had double-clicked rather than clicked+paused+clicked. The only way I can select the name of the file/folder to edit it is to click+long pause (like 3 seconds)+click. Then the text is selected as desired. It's as though the clicks are being recognized (by whatever in the OS recognizes clicks) as much faster than actually made.  There is a similar problem in any program I use that permits text editing, whether Word (Office 2011 for Mac), TextEdit, etc. I have to consciously slow down my cursor/click behavior when selecting text. If not, my actions are misinterpreted as double clicks. This text selection behavior also disappears when using a "Guest" user account, only appearing in my own user account. I Using a different mouse has no effect.
    Steps taken so far. I've Repaired Disk Permissions and Verified Disk using Disk Utility, have Safe Booted, and have turned off all login items in my user account,and recently installed the 10.6.8 supplemental update, all to no avail. Any suggestions or has anyone had and solved this/these problems?

    I think my problem has been that in Sytem Preferences>Mouse, my "Double-Click Speed" was set to the SLOWEST setting. After some experimentation, I now have the that setting two notches from the "Fast" end of the scale. In case it's important, the "Primary mouse button" in my Preferences is set to "Left".
    This not only solves the text selection issues described, but also seems to eliminate the strange "resolving alias to" problem.
    [For the curious, I have a Logitech Performance MX wireless mouse which can be configured with "Logitech Control Center". But the LCC software doesn't control double-click speed; this setting can only be made in the Mouse System Preference pane.]

  • How do you turn off the auto select behavior when working with shape layers?

    How do you turn off the auto select behavior when working with shape layers?
    I am using either of the path selection tools to select only some of the paths on the layer. I have the proper layer targeted. I have the selection too auto select option turned off.
    If another layer has a path in that area, that layer becomes auto targeted and I get the wrong path. Turning off the layer is the only way to avoid this but then I have to  turn on the layer back on between making my selection and transforming to use the other layer as guide. Is there any way to stop this auto select? Locking the other layer does not stop the auto select, just prevents editing.

    As far as i know the move tool options don't have any effect on the path selection tools.
    You might try clicking on one of the path points or on the path itself with one of path selection tools and if you want to select multiple points
    you can shift click with the Direct Selection Tool or Alt click to select the entire path.
    more path shortcuts:
    http://help.adobe.com/en_US/photoshop/cs/using/WSDA7A5830-33A2-4fde-AD86-AD9873DF9FB7a.htm l
    http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-7391a.h tml

  • How to modify a select option without range and mutiple selection??

    hi all,
    i need to modify a select option by removing the range and option for multiple entry. i other words i need to make select option as parameter.( because i cannot use parameter in my program due to some constraints.)
    is it possible to change the select option as per my requirement if yes please let me know how is it possible.
    Thanks in advance.
    Sreekanth.

    hi,
            Yes u can use code like following way..
    select-options : s_matnr for mara-matnr no-extension no intervals.
    Reward if helpful.
    Regards
    Gagan

  • Modifying the selection screen in an LDB

    Hello Experts,
       I have a requirement wherein, i need to copy a standard report which used an LDB 'ERM', into a z report and modify its selection screen(Add a check box).
    Is this possible?
    If yes, can you tell me how?
    Thanks in advance,
    Regards,
    Ravi

    Hi ravi,
    1. simple
    2. just add your single line code for checkbox.
    3. It will automatically come
       beneath the standard selection screen of ldb.
    regards,
    amit m.

  • Modify the selection screen for the transaction VF04

    Hi all,
    My requirement is as follow . I need to modify the selection screen (1000) in such a way that I need to add three more fields to te existing selection screen and make some check boxes checked by default which are unchecked . I have found out all the exits in this development clas VF .  I am listing them out here .
    J_3RSINV  Export Sales
    SDVFX001  User exit header line in delivery to accounting          
    SDVFX002  User exit for A/R line (transfer to accounting)          
    SDVFX003  User exit: Cash clearing (transfer to accounting)        
    SDVFX004  User exit: G/L line (transfer to accounting)             
    SDVFX005  User exit: Reserves (transfer to accounting)             
    SDVFX006  User exit: Tax line (transfer to accounting)             
    SDVFX007  User exit: Billing plan during transfer to Accounting    
    SDVFX008  User exit: Processing of transfer structures SD-FI       
    SDVFX009  Billing doc. processing KIDONO (payment reference number)
    SDVFX010  User exit item table for the customer lines              
    SDVFX011  Userexit for the komkcv- and kompcv-structures           
    V05I0001  User exits for billing index                             
    V05N0001  User Exits for Printing Billing Docs. using POR Procedure
    V60A0001  Customer functions in the billing document               
    V60P0001  Data provision for additional fields for display in lists
    V61A0001  Customer enhancement: Pricing          
    Going with the descrition I dont see any of them suits my requirement .  But there should be an approach . Can anyone please help me to find out an exit or explain me how do we identify an exit to modify the selection screen of an standard ransaction .
    Regards,
    Varun .

    Hello,
    I would suggest you to go for BADI,
    Follow the below steps to find out what all BADI's are called when you press any button in any transaction.
    1) Goto se24 (Display class cl_exithandler)
    2) Double click on the method GET_INSTANCE.
    3) Put a break point at Line no.25 (CASE sy-subrc).
    Now
    4) Execute SAP standard transaction
    5) Press the required button for which you need to write an exit logic, the execution will stop at the break point.
    6) Check the values of variable 'exit_name', it will give you the BADI name called at that time.
    7) This way you will find all the BADIs called on click of any button in any transaction.
    Regs,
    Venkat

  • Overriding Default JTable Selection Behavior

    I'm attempting to override the default selection behavior of a JTable. For clicking, I want the table to behave basically as if the ctrl key was being held down all the time. That works great.
    I want the behavior of dragging a selection to behave a certain way as well. If ctrl is not held down, then a drag should cancel the current selection and start a new one at the drag interval. This works fine too.
    However, if ctrl is held down during a drag, I want the dragged interval to be added to the selection instead of replacing it. This almost works. However, if I hold ctrl while dragging, it no longer let's me "undrag" the selection: once a cell is inside the dragged interval, it's selected, even if you drag back over it to deselect it.
    I understand why that's happening given my approach, but I'm looking for a way around it. Does anybody have any ideas about how to get a JTable to behave the way I want?
    Here's a compilable program that demonstrates what I'm doing:
    import javax.swing.*;
    import java.awt.event.*;
    public class TestTableSelection{
         boolean ctrlDown = false;
         JTable table;
         public TestTableSelection(){
              JFrame frame = new JFrame("Test Table Selection");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //give the table random data
              String [][] data = new String [10][5];
              String [] names = new String [5];
              for(int i = 0; i < 5; i++){
                   names[i] = "C: " + i;
                   for(int j = 0; j < 10; j++){
                        data[j] = "t: " + (int)(Math.random()*100);
              table = new JTable(data, names){
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             super.changeSelection(rowIndex, columnIndex, toggle, extend);     
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              //keep track of when ctrl is held down
              table.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        ctrlDown = e.isControlDown();
                   public void keyReleased(KeyEvent e){
                        ctrlDown = e.isControlDown();
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(250, 250);
              frame.setVisible(true);
         public static void main(String[] args){
              new TestTableSelection();
    Let me know if any of that isn't clear.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    This change seemed to work for me
              table = new JTable(data, names){
                   int prevRow = -1;
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             if ( rowIndex != prevRow ) {
                                  prevRow = rowIndex;
                                  super.changeSelection(rowIndex, columnIndex, true, false);
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              };

  • JList selection problems

    I'm having problems with JList selection - it's really wierd.
    I have a Jlist and on different selections I want to do stuff - well, I do see the GUI line get highlighted but everytime my ListSelectionListener is called the selected index stays 0.
    also, it always calls the ListSelectionListener twice for every selection I make.
    here's how my code looks:
    (typesList is my JList)
    typesList.setSelectedIndex(0);
    typesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    typesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {       
            int newSelection = typesList.getSelectedIndex(); //this returns always 0!        ...
          }

    Look at the line getValueIsAdjusting... (only one selection is processed. And, this code works and provides proper index.
        * Method to load all Tables from Database user
        public void loadTables() {
            // run Database request
            tableListModel = getListModelData("select object_name from user_objects where object_type = 'TABLE'");
            // now plug List with Model
            tableList = new JList(tableListModel);
            tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tableList.setSelectedIndex(0);
            //tableList.addListSelectionListener(this);
            tableList.addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged( ListSelectionEvent e )
                        if(e.getValueIsAdjusting()) return;
                        String tablename = tableList.getSelectedValue().toString();
                        showColumnData(tablename);
                        displayAllTableData(tablename); //intensive (reworking)
            jScrollPane1.add(tableList);
            jScrollPane1.setViewportView(tableList);
            showColumnData(tableList.getSelectedValue().toString());
        }PiratePete
    http://www.piratepetesoftware.com

  • Spry with DW insert, modify and delete behaviors

    I posted this question before and didn't get a response. I'm
    wondering if there is any documentation available for using Spry
    with DW insert, modify and delete behaviors? I'd like to be able to
    perform these functions without having to go from list to master to
    detail page as in traditional ASP etc. According to Alex July at
    Linecraft this is one of "many hidden features" in Spry.
    http://www.linecraft.com/b2/index.php?p=28&c=1

    "LAGooner10" <[email protected]> wrote in
    message
    news:fk71ad$5c7$[email protected]..
    >I posted this question before and didn't get a response.
    I'm wondering if
    > there is any documentation available for using Spry with
    DW insert, modify
    > and
    > delete behaviors? I'd like to be able to perform these
    functions without
    > having to go from list to master to detail page as in
    traditional ASP etc.
    Here you can find an article that covers data update:
    http://www.adobe.com/devnet/dreamweaver/articles/edit_data_in_ajax.html
    The server-side code is CFML, but the concept is the same.
    A more complete demo, with search, insert, update and delete
    is available
    here (code only, no article):
    http://www.massimocorner.com/spry/dynamic_spry.zip
    Massimo Foti, web-programmer for hire
    Tools for ColdFusion and Dreamweaver developers:
    http://www.massimocorner.com

  • Disabling List View selection behavior

    Hi,
    I am using List view to display some text rows. I need the scroll bar on the right and the Sort option on top of the list but I would like to disable the selection behavior of each row. I am just using the rows for display purpose but the availability of hand-mouse pointer on each row is misleading as it lets the user to think that some action would be available if they click the mouse on a particular row. So I want to take this hand pointer off. Is there any other alternative to provide display of a table of items with a scroll bar or disable this behavior of List View ? Please help.
    Thanks,
    Veena.

    Hi Veena,
    I guess you are using Xcelsius4.5, right? (Because in X5 there is no hand-mouse point.)
    If you are using X4.5, As I know, hand-mouse point couldn't be disabled and there is no scroll bar for table component. But there maybe a walk-around for list view component:
    1.Set the color of "Mouse Over Text" and "Selected Text" to black or other same color;
    2.Set the color of "Selected Fill" and "Mouse Over Fill" to white.
    Then when mouse over a row or select a row, there will be no color effects.
    If you are using X5, you can set Table's scroll bar property in Behavior tab.
    Best regards

  • Limit JTable selection behavior

    I have a simple table with 3 columns an multiple rows. If I select a row with the left mouse button and, with out letting go, move the mouse pointer up to a higher row or down to a lower row the currently selected row changes to the row the mouse pointer is over.
    I need to stop this behavior.
    If I select a row with a left mouse press and move the mouse around when I do a mouse release I want the selected row to still be the one i did the mouse pressed action over.
    Please Help.

    This change seemed to work for me
              table = new JTable(data, names){
                   int prevRow = -1;
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             if ( rowIndex != prevRow ) {
                                  prevRow = rowIndex;
                                  super.changeSelection(rowIndex, columnIndex, true, false);
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              };

  • JList selection is listened twice

    Hi
    How to make JList selection listener to catch selection events for only one mouse click (mouse pressed or mouse released)

    Hi,
    you are right!
    first time e.getValueIsAdjusting() is true second time
    it is false. It does not corrspond to mousePressed or mouseReleased. I think the first is an item loosing selection and the second is another item getting selection (just a guess).
    Phil

  • How to 'veto' a jList selection change

    Hi All,
    I have a JList which I'm using as a record selector - so whenever my user selects an item on the list, the associated record is loaded up into the other controls on this form for editing. If the user edits any of the data items, I want to ask whether to save changes or not if another item is selected from the JList. So, I've added code in my 'selection changed' function to check for changes and show a 'yes/no/cancel' JOptionPane. The code for my 'yes' and 'no' respones work fine - either save the changes or not, then show the next record. My problem is handling if a user clicks cancel...
    If the user selects 'Cancel', I dont want any of my "show new record" code to execute (this is easy, I can just 'return' out of the function) but also I don't want the JList selection to change. I've tried calling setSelectedIndex() back to the originally selected item, but this in turn triggers my 'selection changed' function to be called again, which causes the user to be asked twice whether they want to save changes!
    So, what I'm after is a kind of beforeSelectionChanged event, which allows the possibility of denying the selection change - but it doesn't look like this exists! I vaguely remember another language (possibly C++/MFC) having this - the user's action could be ignored depending on the return value of the function. Can anyone offer a way of achieving this in Java?
    (It's been a while since I last touched Java, and I'm a complete n00b with Swing. Using NetBeans as my IDE.)
    Thanks in advance for any suggestions!
    Andy

    The way I do it, is to implement a VetoableSelectionModel similar to a bean with a vetoable property: on selection change it queries registered VetoableChangeListeners if they don't object and backs out if one of them barks.
    HTH
    Jeanette

  • Selecting Behavior property of the Call Behavior Action on a UML Activity Diagram

    I have 16 projects in my UML solution, and I need to be able to select a Behavior in the Call Behavior Action property that is in one Activity Diagram, from a list of Activity Diagrams that are located in different projects, but still in the same overall
    Solution.  Currently, it looks like I can only select Behaviors from within the same project.

    This is related to TFS.  I am using Visual Studio 2013, Ultimate.
    It would be more meaningful if I could insert an Activity Diagram into another Activity Diagram, which is similar to what I can do with an Activity Diagram into a Use Case Diagram.  However, TFS will not allow that.  Instead there is the option
    of using the Call Behavior Action.  When I use this item from my toolbox, I can open the Properties for it and select from a list of "Behaviors" (i.e. Activity Diagrams) that are located in the same Project.  I want to select an Activity
    Diagram from a different Project, but still within the same Solution.  Here is a picture:
    These diagrams are all within the same project.  I want to be able to select a diagram from a different project within the same Solution.  For example, select a diagram from Cash Management as the "Behavior" for an item in the Dealer
    License Project.  They are both in the same Solution, so it seems like I should be able to do that.
    Thanks for any advice.
    Jeff
    Jeff

Maybe you are looking for

  • Report using PDF

    i want to know whether Acrobat Reader which displays the files using PDF extension is included as a part of Internet Explorer or does Acrobat reader needs t obe installed separately. Please help in solving my doubt.

  • Windows 7 no load

    iTunes doesn't load on Windows 7 - - it "rolls back"  any hints?

  • JPanel as Image

    Hi everyone....im now writing here cos i m wondering what is the easiest way to save content of JPanel as jpg , gif or any other image...cos thats basically a file with certaing extension. I would like to save this content of JPanel through JFile Cho

  • Searching for keyword "Ford" in Mail app, shuts down the app with no response

    Hi, I searched my mails with Keyword "FORD", and then the mail app just shuts down without any response. Please check the diagnostic code for more information. Provide me with solution asap. Vivek

  • Tracking of surplus material

    Dear All, Our client is in construction business and have operations across India. The Spares parts inventory maintaned for construction equipments. Now after analysis it is found that very high value items didn't moved / consumed for more than 1 yea