LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-28-2008, 03:47 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
java list selection ordering:


Hello all,

I am trying to make a list box so when you scroll down in it using the arrow keys and hit the bottom it takes you back up to the top of the list again, however when I get to the bottom of the list and hit the down arrow again it scrolls to the second item in the list!


Code:
82     private void lstLastActionKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_lstLastActionKeyPressed
 83     {//GEN-HEADEREND:event_lstLastActionKeyPressed
 84
 85         int keyDown = java.awt.event.KeyEvent.VK_DOWN;
 86         int keyCode = evt.getKeyCode();
 87
 88
 89         log.slog( "Selected Item: " + Integer.toString( lstLastAction.getSelectedIndex() ) );
 90
 91         log.slog( "Last Keypress: " + Integer.toString( evt.getKeyCode() ) );
 92
 93         if( java.awt.event.KeyEvent.VK_ESCAPE == evt.getKeyCode() )
 94         {
 95
 96             log.info( Integer.toString( evt.getKeyCode() ) );
 97
 98             this.dispose();
 99
100         }
101
102         if( keyCode == keyDown )
103         {
104
105             log.slog( "Selected: " + lstLastAction.getSelectedIndex()
106                             + ", last Item: " + ( lstLastAction.getModel().getSize()-1 ) );
107
108             if( lstLastAction.getSelectedIndex() == ( lstLastAction.getModel().getSize()-1 ) )
109             {
110
111                 log.slog( "Waiting for key: " + keyDown + ", Key pressed: " + Integer.toString( keyCode ) );
112
113                 log.info( "End of list." );
114
115                 lstLastAction.setSelectedIndex( lstLastAction.getFirstVisibleIndex() );
116
117             }
118
119         }
120
121     }
thanks, trscookie.
 
Old 01-29-2008, 07:55 AM   #2
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
I have noticed that for some reason the index of the list box is not in order, the index does not seem to represent the number of the item in the list:


Code:
Last Keypress: 40
Selected: 0, last Item: 4
Selected Item: 1
Last Keypress: 40
Selected: 1, last Item: 4
Selected Item: 2
Last Keypress: 40
Selected: 2, last Item: 4
Selected Item: 3
Last Keypress: 40
Selected: 3, last Item: 4
Selected Item: 4
Last Keypress: 40
Selected: 4, last Item: 4
Waiting for key: 40, Key pressed: 40
End of list.
Selected Item: 1
Last Keypress: 38
Selected Item: 0
Last Keypress: 40
Selected: 0, last Item: 4
BUILD SUCCESSFUL (total time: 1 minute 28 seconds)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java threads and loops through a List sniff Programming 4 08-08-2007 05:03 AM
Java - problems with selection sort gomez6211 Programming 1 09-23-2006 12:54 AM
Extract selection list from another site matthewchin Programming 1 12-05-2005 09:14 PM
Low RPM List Selection For LE2005 EHCanadian Mandriva 2 06-23-2005 03:36 AM
What should you know before ordering another harddrive for Linux? Mackan Linux - Hardware 6 11-26-2003 12:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration