是否选择了活动选项卡式收音机?
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TabbedPaneExample {
JFrame f;
TabbedPaneExample(){
f=new JFrame();
JButton check = new JButton("Check state of RadioButton");
check.setBounds(50,280,200,60);
//selected tabbed radio button is selected ?
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JRadioButton rb1 = new JRadioButton("Radio");
JRadioButton rb2= new JRadioButton("Radio");
JRadioButton rb3 = new JRadioButton("Radio");
rb1.setBounds(150,170,80,100);
rb2.setBounds(150,170,80,100);
rb3.setBounds(150,170,80,100);
p1.add(rb1);
p2.add(rb2);
p3.add(rb3);
JTabbedPane tp=new JTabbedPane();
tp.setBounds(50,50,200,200);
tp.add("main",p1);
tp.add("visit",p2);
tp.add("help",p3);
check.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Q: is the radio button of the selected tab is checked
// what is the logic i can put here to get result
// show result into JOptionPane
}
});
f.add(tp);
f.add(check);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new TabbedPaneExample();
}}
问:显示活动选项卡的单选按钮状态(选中或未选中):
我有三个选项卡,这些选项卡有单选按钮,我想获取状态(选择或相对于任何活动选项卡的单选按钮!
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TabbedPaneExample {
JFrame f;
TabbedPaneExample(){
f=new JFrame();
JButton check = new JButton("Check state of RadioButton");
check.setBounds(50,280,200,60);
//selected tabbed radio button is selected ?
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JRadioButton rb1 = new JRadioButton("Radio");
JRadioButton rb2= new JRadioButton("Radio");
JRadioButton rb3 = new JRadioButton("Radio");
rb1.setBounds(150,170,80,100);
rb2.setBounds(150,170,80,100);
rb3.setBounds(150,170,80,100);
p1.add(rb1);
p2.add(rb2);
p3.add(rb3);
JTabbedPane tp=new JTabbedPane();
tp.setBounds(50,50,200,200);
tp.add("main",p1);
tp.add("visit",p2);
tp.add("help",p3);
check.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Q: is the radio button of the selected tab is checked
// what is the logic i can put here to get result
// show result into JOptionPane
}
});
f.add(tp);
f.add(check);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new TabbedPaneExample();
}}
Q: show radio button state(selected or unselected) of the active tab:
I have three tab and these tab have the radio button, I want to get state(selected or unselected) of the radio button with respect to any active tab!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论