Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding a tiny part of look and feel.

Status
Not open for further replies.

Coderifous

Programmer
Dec 13, 2001
782
US
In my system I have a JList that displays values LIKE:
Code:
Foo
Bar
Baz
1023
10432x
11101
11200
113
114
117
213
232
And my users like to use the type-ahead type functionality provided by the basic look and feel package. So if the user wants to select the "232" value, the user merely begins typing "2" (and the 213 is highlighted), and then a "3" (and the 232 is highlighted), and at that point they can hit enter, or tab off, or whatever they wish to do.

The problem comes in when the user wants to select the 11101 value, and the user types "111" in quick succession and they are promptly plopped onto the "113" value. This is correct and consistent behavior for the standard look and feel. It's even commented as such in the Swing library:
Code:
javax.swing.plaf.basic.BasicListUI$Handler.keyTyped(KeyEvent)

The relevant code looks like this:
Code:
if((prefix.length() == 1) && (c == prefix.charAt(0))) {
   		    // Subsequent same key presses move the keyboard focus to the next 
   		    // object that starts with the same letter.
   		    startIndex++;
 		}

So, what I'd like to do, for my one special JList, is have a different handling of the keyTyped event.

I'm a relatively unfamiliar with the Look'n'Feel libraries - in terms of if there is an easy way to replace a portion of the default behavior with my own custom behavior, via subclassing, dynamic redefinition, or whatever.

Thanks for any advice in advance.

--jim

"I know how I'd do it in Ruby
 
Well, I don't have a deep knowledge of that class, but can't you just override that class and reimplement that method?

Cheers,
Dian
 
Hi Dian,

I'd love to subclass it, but I don't know how to 1) subclass an inner class (Handler is inner-class to BasicListUI) or 2) how to tell JOptionPane swing constructor to use my special subclassed look'n'feel class, instead of the default one.

Any clues?

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top