Reputation: 653
I have a JFrame
that contains a JTabbedPane
that has two tabs and a Button
. The first pane consists of a series of JRadioButton
s and the other one consists of a JTextField
.
I want the button to go to the next frame only if
I have implemented the functionality to go to the next page. How can I check for my conditions?
Upvotes: 0
Views: 149
Reputation: 103135
Use getSelectedIndex() method of the tabbedpane to determine which tab is currently selected. Use getSelectedComponent() method to get the component that is currently selected.
Once you have the selected component it depends on how you structure the components such as your radio buttons etc. You can access them and determine if they are selected or not.
If you have a JTextField named textfield then you can:
if(textfield.getText().trim().equals("")){
//nothing was entered
}
to determine if any text was entered.
For the radio button use the isSelected() method to determine if it was selected or not.
Upvotes: 1
Reputation: 23629
Add logic to the button to determine the selected tab and either check the text field or the radio button. Only move to the next page if your criteria is met.
You might even want to create an interface that the tab component implement that report back true/false if the internal components are valid/not valid.
Upvotes: 1