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.
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
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
Related
I have a tab pane that contains a bunch of tabs (obviously). Normally you can set a listener to each tab by calling setOnSelectionChanged() on the Tab. However, if the TabPane is being reorganized in some way, the tab pane automatically selects the first tab in the list. This is causing some performance issues for me so I would like to know if there is a way to know if a Mouse Click caused the Tab to be selected. Apparently tabs cannot have onMouseClick() listeners.
Whilst the solution to the answer wasn't found since tabs aren't actually nodes and don't have mouse click listeners, the performance issues were solved.
When changing tabs, I was (lazily) recreating the entire view and applying the model to the view. This caused a delay of approximately 140ms or more every time the tab changed. It was a bigger issue when implementing a search box to find the correct tab because as the tabs were being recreated from the search, the views were being recreating as the selection of the tabs changed (Tab pane automatically selects the first tab when adding new tabs).
Ultimately the design was changed to having the controller create the view once, and simply hooking the model to the view as the tab changed instead of recreating the view over and over.
I highly recommend looking at this post if your having performance issues and are relatively new to MVC/JavaFX programming:
Scene loads too slow
Currently changing tabs take approximately 15ms which is a significant improvement!
I have an accordion pane which contains three titled panes. I wish to delete these in the java program, however the Accordion object doesn't seem to have a clear or remove method to do this.
I have tried some ways to get around this such as the following:
if (!measureAccordion.getChildrenUnmodifiable().isEmpty()) {
ObservableList<javafx.scene.Node> accordionContent = measureAccordion.getChildrenUnmodifiable();
accordionContent.clear();
}
But this raised an UnsupportedOperationException.
If you check here accordion in javaFX , you will see that the accordion object has a method, getPanes(), which returns an ObservableList of TitledPane. The ObservableList has a lot of methods that you could use such as removeAll. You can see here the documentation for ObservableList.
Accordion is a control that can contain only TitledPane components. So if you want to modify content of Accordion then use Accordion#getPanes method.
I have created a simple tabpane which is using two tabs one has the menu the other one does have the simple game. My question or rather problem is that i am using stackPane. When I use it for my second tab it over layers the buttons. Also I cannot add a simple picture which is weird. I am using javafx
any code example would be appreciated
I have a function that runs in the background and adds tabs in a QMdiArea. However, when a new tab is added it steals the focus from the currently active tab. Is there a way I can add a new inactive tab (sub window), so I keep the focus to the currently used tab?
I have searched the web but was not able to find anything related to this issue.
I have tried the following:
MyWidget *widget=new MyWidget();
QMdiSubWindow *sub=ui->mdiArea->addSubWindow(widget,Qt::SubWindow);
sub->setWindowState(Qt::WindowNoState);
but it does not have the desired effect.
I got help in another forum and found the solution to that problem:
QMdiSubWindow *previous = ui->mdiArea->activeSubWindow();
QTextEdit *edit=new QTextEdit;
QMdiSubWindow *sub=ui->mdiArea->addSubWindow(edit,Qt::Window)
sub->show();
if (previous==0)
ui->mdiArea->setActiveSubWindow(sub);
else if (previous->isWidgetType()) //I check if previous is widget, because if you close the previous tab, when the new one is opened the program crashes on the next line because previous no longer exists.
ui->mdiArea->setActiveSubWindow(previous);
In my APPlication I have to show filter option (as filter option in xls)in Qtable widget for this
I have used tool Button( with property "QToolButton::MenuButtonPopup") to display Menu List and
Upon First Click upon Menu arrow it should show Menu list and selection of any of the Menu it should show only row having the text.
This functionality works fine.
But if Nothing is selected from Menu list and user has clicked Menu arrow second time then list should be hidden but in my case
application crashes giving error:
ASSERT failure in QList::operator[]: "index out of range", file ........\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qlist.h, line 447
I have written below code:
QToolButton *lToolButton = new QToolButton();
lToolButton->setPopupMode(QToolButton::MenuButtonPopup);
lToolButton->setAutoRaise(true);
lToolButton->setText("Filter");
QMenu *lMenu = new QMenu();
QAction *lAction = new QAction("All",this);
lMenu->addAction(lAction);
lToolButton->setMenu(lMenu);
Please let me know what is wrong in my coding.
Can you run your app in the debugger and find at what line in your code (not in Qt's code) the error is happening? The problem should then because more obvious.