This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

FocusListener problem  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm developing a text editor and when it starts,it displays the main window, toolbar and menubar and this is it.
When the user create a new file, it creates dynamically a JTextPane on a JScrollPane on a JTabbedPane, it is possible to create as many file as you want and close as well one by one and all of them.
I would like when the user creates a new file, it will create a new tab with the scrollable textpane and it will get the focus on the textpane, when it creates another one; the same, the focus will be on the new textpane, when the user clicks on one of the tabs the textpane will get the focus and when the user closes one of the tabs, one of the tabs next to it will comes up and the textpane will get the focus. At the moment I've been trying to do this using a changeListener and adding it to the tabbedpane, but it doesn't work well. whe you create the first tab, the textpane get the focus but the caret doesn't blinck and whe you whan to close the right most tab, the next tab that get selected, its text pane doesn't get the focus.
it is better to do the same using a focus listener and adding it to the textpane? or creates a new focusmanager or is it better to do it with the change listener?
here is the code of the tabbedpane class, there is another class that extends a JFrame and has an instance of this class (TabbedPane)

many thanks, I hope it was clear what is the problem.
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some code that does what you want...

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!