Using JavaFX 2.2 I have a window which consists mainly of a TabPane with 4 Tabs. The user may make changes to data presented in any of the tabs, and if they do, I want to make sure they don't loeave that tab until they've saved/cancelled/updated the data. In particular I want to make sure they don't select a different tab. I can catch if they're trying to quit or execute some menu item, but I can't seem to find a way to interrupt a tab change. I can catch when they've clicked on a new tab (onSelectionChanged), and ask if they really want to discard their edits, but then the tab change happens anyway.
Help greatly appreciated.
You can disable other tabs until user clicks 'Save' or 'Cancel'
Get the selection model of the tab pane, monitor it's selected index property for changes and, when you detect a change ask your tab if it is ok to change now - if not, set the selected index back to the currently selected tab, overriding the selection change to a new tab.
Related
I am trying to create a tab system, with similar function to tabs in Chrome, where there is a cross on each tab to close it, like this:
With JavaFX, I can get close, by setting the tabpane closing policy to ALL_TABS. Unfortunately this means my new tab button (also a tab iself) can be closed:
I am aware of the SELECTED_TAB rule, which would fix this problem, but this would defeat the purpose. I am not aware of any other closing policy that would allow exceptions to the ALL_TABS rule.
I tried adding my own cross to each tab individually using the setGraphic method for the Tab class, however I couldn't figure out how to handle that mouse click event such that it closed the correct tab.
I realise I could also make the new tab button something other than a tab, but I wouldn't really know how to integrate that with the tab pane.
So, is there a simpler method that I'm not seeing? If not, then how can I achieve this kind of tabbing system in JavaFX?
plusTab.setClosable(false);
I did a simple skim of the documentation. Will this work?
I work with swing to build GUI. Hello everyone
I have 2 tabs (JTabbedPane) that I want to synchronize.
For example, on the image below, I would like that if I click on the Rent button, the line can be automatically added to the My leasing tab so that if I go to the My Leasing tab, I find the line that has just been added.
Currently, to see the line that has just been added to the My leasing tab, I must log out and log back in.
I tell myself that there may be a listener to put in place but I do not know which one.
You need to respond to the click of the "Rent" button.
Check out the Table Button Column. This class allows you to add an ActionListener which is invoked whenever the button is clicked (or activated by using the space bar).
The example code shows how to delete a row from the model. In your case you would want to copy the data from one model to the other.
Google Chrome Recently had an update that added an extra button onto to the top of the window that allowed you edit your account settings. I have a great use for an extra button like this one but I do not know how to make it. So, how can I add an extra button at the top of the window?
This is what I would like to do or have in mind.
This is more of an amateur/simple answer but it could be possible just to make a title bar with all of the drop downs without text until you reach the button you want and customize that
The problem I am facing right now is that I want a particular tab on the tabbedfolder to be the active one on click of a button. I have tried the setFocus() method on the composite contained in this tab but it is not working how to do so?
Try to use
tabFolder.setSelection(tabIndex/tabItem)
Also, you may want to use
tabItem.getControl().setFocus()
Hope this helps.
I have a menu with a few JCheckBoxMnuItems. How do I ensure that the Menu stays open until I have done all my selections (i.e. checked the menuitems) and does not close on just clicking one of them?
I'd rather not try to change the normal menu behavior for an application or for a part of the menu tree. A User expects that the menu closes automatically after a menu item is clicked. And, if you kept the menu expanded, what kind of action would you invent to close it manually after you've done your last selection?
If there's a requirement to change more then one setting within one use case, then you should consider to provide a small dialog where the use can apply the changes and confirm them at once. I believe, that's more consistent with typical behaviors of UIs.
And it declutters the menu bar, you'll have just one 'setup' menu item instead of a dozen (?) check box actions :)
I guess menu's aren't supposed to allow multi-selection.
But you may offer keyboard shortcuts to set the menuitems without using the menu at all.
If the set-operation of your flags is a central aspect in your application, I would tend to use a dialog here. These are all suggestions which do not require to change the internal implementation of the existing controls, even though I know, that it would be possible in swing.
I agree that it is better to do this with standard UI. However, if do you want to add checkboxes that do not close the menu it is surprisingly easy:
JCheckBox checkBox = new JCheckBox("Text");
checkBox.setOpaque(false);
checkBox.setRequestFocusEnabled(false);
menu.add(checkBox);
This may not work on every look and feel and the check boxes will not line up with menu items in the same manner as JMenuItems but it seems to be a reasonable place to start.