Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Swing / AWT / SWT
Focus problem
miguel lisboa
Ranch Hand
Posts: 1282
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Since
setNextFocusableComponent(component)
is deprecated, how can i control the focus on my components?
thanks in advance
java amateur
Craig Wood
Ranch Hand
Posts: 1535
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here's a page from the Swing trail in the
java
tutorial that deals with focus:
How to use the Focus Subsystem
miguel lisboa
Ranch Hand
Posts: 1282
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot
that really helped
to those with the same problemas i had, here's what i did:
created this class:
import java.awt.*; class Foco extends FocusTraversalPolicy { TesteVisual visual; Foco(TesteVisual v) { visual = v; } public Component getComponentAfter(Container focusCycleRoot, Component aComponent) { if (aComponent.equals(visual.txtAno)) { return visual.txtTurma; } else if (aComponent.equals(visual.txtTurma)) { return visual.txtNomeUtilizador; } else if (aComponent.equals(visual.txtNomeUtilizador)) { return visual.txtPalavraPasse; } else if (aComponent.equals(visual.txtPalavraPasse)) { return visual.txtEpoca; } else if (aComponent.equals(visual.txtEpoca)) { return visual.lstEpocas; } else if (aComponent.equals(visual.lstEpocas)) { return visual.lstTurmas; } else if (aComponent.equals(visual.lstTurmas)) { return visual.cmdCriar; } else if (aComponent.equals(visual.cmdCriar)) { return visual.cmdEliminar; } else if (aComponent.equals(visual.cmdEliminar)) { return visual.cmdActualizar; } else if (aComponent.equals(visual.cmdActualizar)) { return visual.cmdSair; } else if (aComponent.equals(visual.cmdSair)) { return visual.txtAno; } return visual.txtAno; } public Component getComponentBefore(Container focusCycleRoot, Component aComponent) { if (aComponent.equals(visual.txtAno)) { return visual.cmdSair; } else if (aComponent.equals(visual.cmdSair)) { return visual.cmdActualizar; } else if (aComponent.equals(visual.cmdActualizar)) { return visual.cmdEliminar; } else if (aComponent.equals(visual.cmdEliminar)) { return visual.cmdCriar; } else if (aComponent.equals(visual.cmdCriar)) { return visual.lstTurmas; } else if (aComponent.equals(visual.lstTurmas)) { return visual.lstEpocas; } else if (aComponent.equals(visual.lstEpocas)) { return visual.txtEpoca; } else if (aComponent.equals(visual.txtEpoca)) { return visual.txtPalavraPasse; } else if (aComponent.equals(visual.txtPalavraPasse)) { return visual.txtNomeUtilizador; } else if (aComponent.equals(visual.txtNomeUtilizador)) { return visual.txtTurma; } else if (aComponent.equals(visual.txtTurma)) { return visual.txtAno; } return visual.txtAno; } public Component getDefaultComponent(Container focusCycleRoot) { return visual.txtAno; } public Component getLastComponent(Container focusCycleRoot) { return visual.cmdSair; } public Component getFirstComponent(Container focusCycleRoot) { return visual.txtAno; } }
note the constructor so that i can control the visual components.
in the gui class (TesteVisual) i added this:
//Construct the frame public TesteVisual() { //... Foco newPolicy = new Foco(this); this.setFocusTraversalPolicy(newPolicy); }
java amateur
miguel lisboa
Ranch Hand
Posts: 1282
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot
that really helped
to those with the same problemas i had, here's what i did:
created this class:
import java.awt.*; class Foco extends FocusTraversalPolicy { TesteVisual visual; Foco(TesteVisual v) { visual = v; } public Component getComponentAfter(Container focusCycleRoot, Component aComponent) { if (aComponent.equals(visual.txtAno)) { return visual.txtTurma; } else if (aComponent.equals(visual.txtTurma)) { return visual.txtNomeUtilizador; } else if (aComponent.equals(visual.txtNomeUtilizador)) { return visual.txtPalavraPasse; } else if (aComponent.equals(visual.txtPalavraPasse)) { return visual.txtEpoca; } else if (aComponent.equals(visual.txtEpoca)) { return visual.lstEpocas; } else if (aComponent.equals(visual.lstEpocas)) { return visual.lstTurmas; } else if (aComponent.equals(visual.lstTurmas)) { return visual.cmdCriar; } else if (aComponent.equals(visual.cmdCriar)) { return visual.cmdEliminar; } else if (aComponent.equals(visual.cmdEliminar)) { return visual.cmdActualizar; } else if (aComponent.equals(visual.cmdActualizar)) { return visual.cmdSair; } else if (aComponent.equals(visual.cmdSair)) { return visual.txtAno; } return visual.txtAno; } public Component getComponentBefore(Container focusCycleRoot, Component aComponent) { if (aComponent.equals(visual.txtAno)) { return visual.cmdSair; } else if (aComponent.equals(visual.cmdSair)) { return visual.cmdActualizar; } else if (aComponent.equals(visual.cmdActualizar)) { return visual.cmdEliminar; } else if (aComponent.equals(visual.cmdEliminar)) { return visual.cmdCriar; } else if (aComponent.equals(visual.cmdCriar)) { return visual.lstTurmas; } else if (aComponent.equals(visual.lstTurmas)) { return visual.lstEpocas; } else if (aComponent.equals(visual.lstEpocas)) { return visual.txtEpoca; } else if (aComponent.equals(visual.txtEpoca)) { return visual.txtPalavraPasse; } else if (aComponent.equals(visual.txtPalavraPasse)) { return visual.txtNomeUtilizador; } else if (aComponent.equals(visual.txtNomeUtilizador)) { return visual.txtTurma; } else if (aComponent.equals(visual.txtTurma)) { return visual.txtAno; } return visual.txtAno; } public Component getDefaultComponent(Container focusCycleRoot) { return visual.txtAno; } public Component getLastComponent(Container focusCycleRoot) { return visual.cmdSair; } public Component getFirstComponent(Container focusCycleRoot) { return visual.txtAno; } }
note the constructor so that i can control the visual components.
in the gui class (TesteVisual) i added this:
//Construct the frame public TesteVisual() { //... Foco newPolicy = new Foco(this); this.setFocusTraversalPolicy(newPolicy); }
And worked perfectly!
thanks again a lot
java amateur
Destroy anything that stands in your way. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
set focus on link without tabindex
Jack Up Browser Viewport
Clean Code A Handbook of Agile Software Craftsmanship - Tools
Refactoring to Patterns - book questions
Popup focus
More...