JCheckBoxMenuItem stays checked when switching tabs - java

I have a pretty basic interface of a chromotagram viewer. In the menu I allow the user to reverse the viewer with a JCheckboxMenuItem. Functionally, it does exactly what its supposed to do. My interface allows for multiple chromatograms to be open at once. I will post a few example pictures as I get to my question.
Above I have one tab opened and have yet to reverse the chromatogram.
Above I have clicked the option and it worked.
Here is my issue. If I open another tab and move to it, the option is still checked even though I have yet to click that button. The easy way out would be just to make it a normal button but I just want to know if there is a way that each tabbed could keep track of if its been reversed yet. Would this require multiple instances of the button itself? If anybody has any suggestions, please let me know. Thank you.

if(centralPara.getNumOpen() > 1){
centralPanel = centralList.get(centralPara.getCurrentFrame());
JCheckBoxMenuItem reverseItem = centralPara.getReverseItem();
boolean reversed = centralPanel.getReversed();
reverseItem.setSelected(reversed);
}
in my tab change listener I check to see that we have atleast more than one tab open. if so get the frame we are currently viewing and the top level menu item. Force it be be selected if that the current view frame is selected, or else force it be unselected.

Related

Clearing a group of radio buttons in Java

I have a program which prompts users to select a choice out of four options (from a group of RadioButtons).
Once the user has made a choice, he/she clicks a button and then receives a message. After closing the window, the user will go back to the first window and make a new selection if desired. What I want is for the radiobuttons to be totally clear.
So far I have implemented a method to actually unselect the radiobuttons and works well (clears the values of the variables), what it doesn't do is to remove the black spot from the previously selected radiobutton. In the other hand this same method works fine with unselecting and unchecking checkboxes.
Any tip to fix this little issue?
Here's my code:
public void clean() {
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false);
jRadioButton4.setSelected(false);
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
}
make them group of buttons and then buttonGroup1.clearSelection();

jcreator - making a matching game

I'm doing a Matching/Memory Game in JCreator using buttons and if-else statements
When you click the buttons, the image clicked will pop up then if you click the next one, but it's not the same image, then both will close. If you get the correct matching image, they both disable. My problem is the logic of matching it.
What will I do or use to make my program know that two buttons match?
You need to add an ActionListener. Use that link to find out how to detect whether buttons are being pushed and what to do when pushed. To make an image appear, use an icon with the button. When you click, a number changes to a value. If you click another and a number is the same value, then they become disabled. If they are diffrent, then the icon is changed and the number reverts to zero. To disable, use button.setEnable(false);
Use this link for help with button icons/general button help.
Another thing you can do, although it takes more time, is giving each button a numeric value and use RandNum to decide them. If you set it as a constant variable then you can use that to match them

Hiding the tabs in a DockableFrame using Jidesoft

I am stuck using JideSoft at the momemnt. I have a DockableFrame, which will have many views on it. I want to hide the tabs that let me switch between views, but I cannot figure out how. Can anybody help?
User can right click on the tab or the title of DockableFrame to select close menu item to close it. If you refer to how to close it using API, DockingManager.hideFrame will do it.
DockableFrame.hideFrame(String frameName) works perfectly.
If you want to hide/unhide a component inside a DockableFrame you'll need to access that component, set the visibility
component.setVisibility(!component.isVisible());
and then ask the parent DockableFrame to revalidate itself.
parentFrame.revalidate();

JTabbedPane: How to restrict user from moving out of current tab

How can I restrict the user from going away from the current tab. I need to show a confirmation message to save/discard changes before leaving the current tab. How can I implement this functionality in a JTabbedPane?
You could override the setSelectedIndex in the JTabbedPane object, as this is called before the change takes place. If you do this, remember to call super.setSelectedIndex after you displayed your confirmation.
Alternatively, as Eng.Fouad states, you could add a ChangeListener and display the confirmation message there, but this happens after the tab has been changed, so your confirmation message would display after the new tab has been displayed on screen:
http://www.java2s.com/Tutorial/Java/0240__Swing/ListeningforSelectedTabChanges.htm
The second option would be easier to implement if you can live with the fact that the new tab will already be displayed when the confirmation pops up.

Embedding JTextArea into a JMenuItem

We are building our own Web Browser in Java. It doesn't have to be anything too complicated, we just want several things to do so we could distinguish our project from others.
What we want to know is this:
Is it possible to somehow embed a JTextField object into a JMenuItem?
To be more precise, we want our address bar (text field) to show when we click on a certain item within our menu.
Well, menu items are used for invoking an Action which causes the menu to close.
So you would just have your menu item Action display a popup dialog or something like that.
Or, if you really want to keep the popup open, the you could probably create a sub menu and then just add the JTextField to the sub menu. Remember, you can add any Component to JMenu.
Or, if you just want the text field to display on the main menu, then you just add the text field to the main menu. Of course you would lose functionality like being able to use the keyboard to navigate up and down the menu list.
All the suggestions are a hack at best, so I agree with the original comment to your question.
It's done in the standard OS X "help" menu, so I wouldn't call it an interface "quirk".
A quick google turned up this old link from 2004:
http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2004-12/0149.html

Categories