1

I just started using JavaFX. In my little Project I got two views. The first is filled with a tabpane, while the second one contains a button to add new tabs to the tabpane. That means I need to switch between the first and the second view to add new Tabs. The tabpane has one standart-tab wich is unable to close.

My Problem: If I add more than one new tab to my tabpane all tabs are painted over each other.

I already triedto prevent it like this: Init everything:

        private ArrayList<Tab> allTabs = new ArrayList<Tab>();
        Tab tab = new Tab();

        allTabs.add(tab);
        TabPane tp = new TabPane();
        tp.getTabs().add(tab);

To set the selection I tried a few things:

        tp.getSelectionModel().clearSelection();
        tp.getSelectionModel().select(allTabs.size());
        _________________________________________________________________
        tp.getSelectionModel().clearSelection();
        tp.getSelectionModel().select(tp.getTabs().size);
        _________________________________________________________________
        tp.getSelectionModel().selectLast();
        _________________________________________________________________
        tp.getSelectionModel().selectNext();
        _________________________________________________________________
        tp.getSelectionModel().clearAndSelect(tp.getTabs().size());;

I want to select the newest tab. This is already working but the old ones aren't deselected. The Problem disappears if I select tabs with a mouseclick.

I'm thankfull for any idea.

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
  • 1
    Can you create and post an [MCVE](http://stackoverflow.com/help/mcve)? I have never seen two tabs "painted over each other" as you describe: it sounds like something else is wrong in your code somewhere. – James_D Jul 28 '15 at 11:26
  • He is right try using the MVC-tutorial for your next questions! – Felix Gerber Aug 17 '15 at 11:48

2 Answers2

0

Is it possible that your using different FXMLLoaders? I had an simular problem while i was using the normal FXMLLoader and a coustom FXMLLoader. Just try to use the same in both cases. This is the way how it works for me.

If it doesn't fix your problem some pictures and some more code-fragments would be helpful to solve your problem.

Greetings

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
  • 1
    Ohhh didn't thought about that. Thanks mate, its totally working now. maybe my Coustom Loader is buggy. –  Jul 30 '15 at 06:46
0

I had similar problem, i just removed the line

 tabpane.getSelectionModel().clearSelection();

No idea why it works. Just keep :

 tb.getSelectionModel().select(index or tab);

or

tb.getSelectionModel().clearAndSelect(index or tab);

PS : tp.getSelectionModel().clearAndSelect(tp.getTabs().size()); this, will do nothing, tp.getTabs().size() is out of bound, so it will

Lion_CH
  • 78
  • 2
  • 8