Java 如何定义大尺寸的JRadioButton?
我在学java。对于我的GUI程序,需要比标准大的单选按钮。我能做什么Java 如何定义大尺寸的JRadioButton?,java,swing,jradiobutton,Java,Swing,Jradiobutton,我在学java。对于我的GUI程序,需要比标准大的单选按钮。我能做什么 我使用最新版本的Java Netbeans IDE。您可以为单选按钮提供自己的图像,请参阅,有关更多详细信息 import java.awt.EventQueue; import java.awt.GridBagLayout; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import javax
我使用最新版本的Java Netbeans IDE。您可以为单选按钮提供自己的图像,请参阅,有关更多详细信息
import java.awt.EventQueue;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class RadioButtonTest {
public static void main(String[] args) {
new RadioButtonTest();
}
public RadioButtonTest() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
public TestPane() {
try {
BufferedImage checked = ImageIO.read(getClass().getResource("/Checked.png"));
Image unchecked = ImageIO.read(getClass().getResource("/Unchecked.png")).getScaledInstance(300, 300, Image.SCALE_SMOOTH);
JRadioButton btn = new JRadioButton("I'm not fat, I'm just big boned");
btn.setSelectedIcon(new ImageIcon(checked));
btn.setIcon(new ImageIcon(unchecked));
btn.setHorizontalTextPosition(JRadioButton.CENTER);
btn.setVerticalTextPosition(JRadioButton.BOTTOM);
setLayout(new GridBagLayout());
add(btn);
} catch (IOException exp) {
exp.printStackTrace();
}
}
}
}
您可以为单选按钮提供自己的图像,请参见,有关更多详细信息
import java.awt.EventQueue;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class RadioButtonTest {
public static void main(String[] args) {
new RadioButtonTest();
}
public RadioButtonTest() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
public TestPane() {
try {
BufferedImage checked = ImageIO.read(getClass().getResource("/Checked.png"));
Image unchecked = ImageIO.read(getClass().getResource("/Unchecked.png")).getScaledInstance(300, 300, Image.SCALE_SMOOTH);
JRadioButton btn = new JRadioButton("I'm not fat, I'm just big boned");
btn.setSelectedIcon(new ImageIcon(checked));
btn.setIcon(new ImageIcon(unchecked));
btn.setHorizontalTextPosition(JRadioButton.CENTER);
btn.setVerticalTextPosition(JRadioButton.BOTTOM);
setLayout(new GridBagLayout());
add(btn);
} catch (IOException exp) {
exp.printStackTrace();
}
}
}
}
你能提供一些显示你尝试过的代码吗?你能提供一些代码来显示你所尝试的吗?也可以考虑引用一个JCufft.SiZeavrand。你对我有很好的建议。@ SaIDh很高兴,它还考虑了一个JCufft.Ssivavrand,引用。“安德鲁。汤普森。我已经考虑过使用JSLe/JxLeCar根据你的需要,你也可以使用JLeal/JxLead来扩展这个组件,感谢每个人。“你的推荐对我很有帮助。”赛德很高兴这一切都有帮助