Avatar billede fredand Forsker
08. december 2008 - 22:00 Der er 3 kommentarer og
1 løsning

How to find out if a tab got Focus?

Hello!

I'm playing around with a JTabbedPane and I need to find out which tab that got focus.

I have tried like this with a state listener:

    public void stateChanged(ChangeEvent e)
    {
        if(e.getSource() == tabbedPane)
        {
            Component[] components = tabbedPane.getComponents();
            for(int i = 0; i < components.length; i++)
                {
                  if(components[i].hasFocus())
                  {
                    System.out.println("HELLO GOT FOCUS")
                  }
                }
...

But it seem not to work.

So if you guys know any nice startegy for this please let me know.
And if you also can explain why my idea did not work that would be most welcome as well.

Best regards
Fredrik
Avatar billede welcor Nybegynder
09. december 2008 - 00:23 #1
Interesting with an english post to a danish site.

You're going the long way about it. JTabbedPane is easier than that.
Just add this to get info on which pane is selected:

  Component selected = tabbedPane.getSelectedComponent();
or
  int idx = tabbedPane.getSelectedIndex();
Avatar billede arne_v Ekspert
09. december 2008 - 04:22 #2
Så vidt jeg ved tilhører han broderfolket på den anden side af Øresund. Og mange
foretrækker at holde dansk-svensk kommunikation på engelsk.
Avatar billede welcor Nybegynder
09. december 2008 - 12:16 #3
Det er fint med mig -jeg er vant til at kommunikere på engelsk...
Avatar billede fredand Forsker
09. december 2008 - 20:18 #4
Hello mates!

Thanks for your replies!
Your solution worked perfect welcor.

Yes I'm from sweden, not so far away. But I must say that some times it is easier to communicate in english, but I acctually have increased my knowledge in Danish alot since I have become a member at eksperten.dk.

I guess that if I tried to post in swedish there would be alot of funny missunderstanding.
Do you by the way got this strange "way of speak" in Denmark:
Swedish - Kan du kasta ett getöga på det här?
Direct into english - Could you throw an eye of a goat on this?
Means - Could you take a quick glance on this issue?

Pretty strange and a bit funny I must say ;-)
I have decided that I will try not to torture you with swedish then ;-)

At my former job we also had alot of employees from foreign countries. Then it helped alot when I could show them all the help I have got from eksperten.dk, mainly from you Arne. And in my opinion I must say that eksperten.dk had not met its match any where on the Internet. I also recomend eksperten.dk to every one that's ask for a good IT-forum.

Also I always need to practice my english so I hope you guys not mind.   

Thanks to you both and see you around!

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester