I am creating a matrix of JRadioButtons (see image below). What I want to do is allow only one selection per row and column. Is there any way I can possibly assigned two button groups to a single button? Or is there any other suggestions how I may do this?
Description: I want the user to select one value from Highest, Normal, Least and Not Available option for Morning, Afternoon and Evening. However, I also want them to limit them to picking only one option from Morning, Afternoon and Evening for Highest, Normal, Least and Not available. So, basically, only one option needs to be selected for each row and only one option for each column, and yes, they can be the same option for the row and column.
Ideas? Suggestions?
You cannot use more than one ButtonGroup for a single JRadioButton. To solve the problem, just check for errors at click button, then display the proper error message if any error encountered.
Another smart idea is hiding per click. Handle click event for each one, so that when a radio button is selected its row and column are hidden setVisible(false) (or at least disabled setEnabled(false)).
Related
I have a situation that I want some advice on. The listeners of a JComboBox all work as I'd expect.
The JComboBox is created using the constructor that takes an array as argument. The argument is an ArrayList which is converted using the toArray method. The JComboBox is setEditable(false) and setEnabled(false). I'm not sure what else to tell you. JDK 1.8, Mac OS X 10.9.5 and (mis)using NetBeans 8.0.2
What is wrong is that although the underlying values and computations happen when you select, say "-4", i.e. all listeners get the value correctly, the GUI does not display "-4" but rather, it displays the previous selection.
This does not happen every time. When it does happen, if I (change the focus?) Cmd-Tab (on a Mac) away or click on another window (any window) and come back, the value displays correctly.
If I click on the drop-down and see the list, the check mark is definitely on the selected item, not the one currently displayed. And when I let go (without selecting) the screen is corrected.
I've done some things to try to get it to update, most are grasping at straws (ItemListener that sets the selected item to the one it just got; repaint() here and there...).
This is annoying to the users. They doubt they have selected, so they select twice. Or they select and move. All logs and debug show the selected item is the one they intended.
One of these JComboBox (dropdowns) has a button beside it, that takes the name selected and loads a set of values from a setup file. One can watch the displayed (and not selected) name change to the selected name when the button is pressed.
Thanks for any advice.
I have a table of forms which accepts first name, last name etc. When I navigate through using the tab key and enter some text in first name, all of the text disappears and that row gets selected. I have tried almost all techniques.
Is there any way we can avoid that using coding?
If I use the mouse then it wont give that error.
Assuming an otherwise correct use of JTable, you may need to terminate the edit when focus is lost, as suggested here and here:
table.putClientProperty("terminateEditOnFocusLost", true);
I have a JTable with row selection enabled. Before today, my desired functionality was for double-clicking on any given row to open up a new window. And before today, that worked just fine.
I've just added a column of JCheckBoxes to the table. Selecting and deselecting individual checkboxes in the new column works fine, in general. However, if I select a checkbox and quickly deselect it, the table interprets my actions as a double-click on the checkbox's row, which is not what I want.
Is there a way to disable the double-clicking behavior for just the checkboxes, but keeping row selection enabled otherwise? If not, how about disabling the behavior for just one column of a table? If so, how?
If not, how about disabling the behavior for just one column of a table?
Use the table.columnAtPoint(...) method to ignore double clicks on the columm with the checkbox.
In the MouseListener you could check the state of the checkbox of the selected row for each click and if the second click's state doesn't match the first click's state then don't open a new window.
I'm writing my 1st Java program (in Netbeans) and I'm lost. I have 2 questions at the moment, if anyone is kind enough to help me.
Here's what the program is supposed to do:
take 1 of 4 "status" options, plus a 5 digit number (both of these items are entered by a user via a touch-screen monitor) and then email this info to someone with the subject line of: "Item #[5 digit number from JFormattedTextField] is currently [1 of 4 possible status options].
Email command would command after user clicks "enter" button, and then user clicks "OK" on a pop-up which asks user to confirm message about to be emailed. As far as my 3rd question, it's about the e-mailing part, and I figured that would be a another thread after I get this button & text field stuff ironed out.
Here's a picture of the touch screen UI I have so far:
(can't post images as a rookie, go to krisbunda.com/gui.png for this image)
Question #1:
the 4 status options (4 JButtons) are wrapped inside of a JPanel. I want the most recent button to have been pushed in the "statusPanel" JPanel to change the background to blue and the button text to white.
Can I put a mouselistener on the button's parent JPanel to listen for click events on the children (the 4 status JButtons), and then whichever button was last clicked, it will turn blue w/ white text? Please point me in the right direction.
Question #2:
I have a JFormattedTextField named "display" that shows the numbers as they're clicked, which are appended from a StringBuffer named "current". I want the text field to only accept a total of 5 numbers.
When I tried putting a mask of "#####" on the field, it would only chime a warning beep when I pushed the number pad's buttons. Currently I've chosen "Category: number" and "Format: custom" and then typed "#####" in the "Format:" field. This allows me to click number buttons and see their text displayed, but it doesn't stop me from typing more than 5 characters.
I'm doing this through the "Properties> FormatterFactory" dialog box. A screen shot is shown below:
(go to krisbunda.com/text-formatterFactory.png to view this image)
And here's the code I have so far:
(my post was too long with this code, so go to: krisbunda.com/java-sampleCode.txt to view)
Thanks in advance for any help!
Your code looks fine, and you already have fields set up to hold references to all your buttons, so now you just need to write the code inside the status setting buttons and then make them call a subroutine with the new status. This subroutine should then reset all the buttons to their default color and then set the special selected color on the button that corresponds to the new or existing status.
Edit: adding code here in response to your comment...
Firstly, never use == with Strings. You MUST use equals() otherwise when you get two Strings that are identical, but are different objects, they will not be the same and your comparisons will fail.
There are much better ways of coding this up, including using enums etc. but this should work for you:
// Reset all the buttons
outsideNotReadyButton.setBackground(...);
loadedButton.setBackground(...);
outsideReadyButton.setBackground(...);
shippedButton.setBackground(...);
// Now set the one of the button's colors conditionally
String status = ...
if(status.equals("SHIPPED")) {shippedButton.setBackground(Color.BLUE);}
else if(status.equals("LOADED")) {loadedButton.setBackground(Color.BLUE);}
// ...and so on
An ActionListener is the more common approach to buttons, as discussed in How to Use Buttons, etc. A FocusListener, also used in this example, is one way to change a button's appearance in the way you describe.
An sscce showing just your JFormattedTextField problem will be more helpful. Several such examples may be found in the article How to Use Formatted Text Fields.
I have a JCheckBox that should not be checked by the user when a certain other field is empty.
So now I want to have an error popup and then reset the checkbox (I've considered disabling the checkbox, but the connection to the other field is non-obvious, and a tooltip text IMO not visible enough).
What's the correct way to do that in Swing? Through a PropertyVetoException? Where do I throw it and where do I catch it? My first (probably ugly) idea would be to add a ChangeListener that itself shows the popup and resets the value.
Edit: The question is about Nikki (screenshot below), an app I am developing which geotags images and exports them to Google Earth's KMZ format. The checkbox is used to select the images to include in the export. But this requires the images to be gotagged first (which in turn requires either a timestamp, or manual assignment). I don't think this requirement can be made obvious through the UI layout.
(source: brazzy.de)
I would simply disable the check box and add a message explaining why the option is not available. A nice way to show the message is to display a mini exclamation mark next to the check box and put the message in a tooltip.
Poping up an exception often feels wrong because users don't read error messages. For most users an error message popup means that the application did something wrong, in your case it's the normal behavior.
Edit if you insist on letting the check box enabled, another way to show the user that some info is missing would be to flash the missing data. Eg. if latitude and longitude are missing and the user clicks on export, set a red background onto these fields for a just a second. This will clearly show the user what's missing.
In this screen, don't you want to put the mouse over the red circle to understand what's going on?
validation http://www.vogella.de/articles/EclipseDataBinding/images/validation10.gif
I don't think the Export JCheckBox should be disabled at all. Instead, the Export JButton itself should examine the current export list and display any anomalous entries in a way that allows navigation to a chosen photograph. If all entries are correct, Export would proceed as usual.
Addendum: It think you are right to keep the interface as non-modal as possible. My model for this would be unsaved files when exiting an editor or uncommitted changes when closing a project in an IDE.
If that's a status line at the bottom of the window, you might indicate the number of photographs currently selected for export, adding a count if any still need geocoding.
The field should simply be allowed to disable the checkbox. If the coupling is unintuitive then the GUI layout may have to be reconsidered.
EDIT: I ran it from your page, and I believe the issue here is that you actually have a third and fourth step in addition to select folder, select images. The third step is validate image, and fourth is select images for export. I think your problem is that this is not clearly conveyed in the current layout, and that reflects in your question.
I would suggest that you create a separate column containing the checkbox for each image, and that THAT checkbox is disabled until the image passes validation (step 3). Perhaps with an explanatory text in the column about why the image hasn't passed yet.