Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Fous Traversal Policy

Reply
Thread Tools

Fous Traversal Policy

 
 
Big Jim
Guest
Posts: n/a
 
      01-27-2006
Sorry to cross post but I've now noticed the gui group doesn't seem to gt
much traffic.

Has anyone written a decent one? (FocusTraversalPolicy that is)

I had an app that worked fine in 1.3, in 1.4 the focussing is a disaster.
I have JDesktop panes, JIternalPanes and JTabbed panes containing JTables,
JComboBoxes, JTextFields etc.

Using ContainerOrderFocusPolicy I can't get initial focus to work, it's take
2 or 3 tabs sometimes to move from one component to the next etc. I guess
it's stepping out to parent panes and then back or something even though
I've set everything to focusable(false) except the items I want to land on.
I wrote a pretty basic policy but it's not handling compound components
properly (a JComboBox I've made AutoCompletable) and I haven't covered any
of the up/down cycle stuff or checked for no enabled components. Does anyone
have anything more complete? (I'm no swing expert)

Cheers, Richard.

from memory ...

import java.awt.*;
import java.util.*;

public class MyTraversalPolicy extends FocusTraversalPolicy {
private Map map;
private java.util.List components;
private int currentKey;

public MyTraversalPolicy(){
map = new IdentityHashMap();
currentKey = 0;
components = new ArrayList();
}

public void add(Component c){
map.put(c, new Integer(currentKey++));
components.add(c);
}

public Component getDefaultComponent(Container focusCycleRoot) {
return getFirstComponent(focusCycleRoot); }

public Component getFirstComponent(Container focusCycleRoot) {
Component c = components.get(0);
return c.isEnabled() ? c : getComponentAfter(focusCycleRoot, c);
}

public Component getLastComponent(Container focusCycleRoot) {
Component c = components.get(components.size() - 1);
return c.isEnabled() ? c : getComponentBefore(focusCycleRoot, c);
}

public Component getComponentAfter(Container focusCycleRoot, Component
aComponent) {
int key = ((Integer)map.get(aComponent)).intValue();
if(key == components.size() - 1){
return getFirstComponent(focusCycleRoot);
}
Component c = components.get(key + 1);
return c.isEnabled() ? c : getComponentAfter(focusCycleRoot, c);
}

public Component getComponentBefore(Container focusCycleRoot, Component
aComponent) {
int key = ((Integer)map.get(aComponent)).intValue();
if(key == 0){
return getLastComponent(focusCycleRoot);
}
Component c = components.get(key - 1);
return c.isEnabled() ? c : getComponentBefore(focusCycleRoot, c);
}
}




 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Policy map using policy map Geoffrey Sinclair Cisco 1 07-27-2009 09:31 AM
TCon 17 teleconverter won't fous. Any tips??? cJ Digital Photography 1 10-04-2006 10:05 PM
Default Domain Policy vs Default Domain Controller Policy Tyler Cobb MCSE 6 10-19-2005 09:36 PM
Default Domain Policy vs. Default Domain Controller Policy Tyler Cobb MCSA 1 10-09-2005 03:42 PM
nat traversal or something else cci admin Cisco 5 04-22-2004 06:32 AM



Advertisments