我创建了一个扩展 JDialog 的组件。它在 JScrollPane 中创建了一个 JPanel(大尺寸)。然后我将 RadioButtons 和 JLabels 添加到 JPanel
两个问题: 1 - RadioButtons 和 JLabels 不显示。2 - JScrollPane 的滚动条不显示
这是我的代码:
public class xuggleJOptionPane1 extends JDialog{
Container pane;
JPanel paneMain;
JLabel ms1;
xuggleJOptionPane1 myFrame;
JPanel panel;
JScrollPane paneScroll;
JPanel paneScrollpanel;
public xuggleJOptionPane1(JFrame parent, String str, int nf)
{
super(parent, str);
myFrame = this;
myFrame.setPreferredSize(new Dimension(400, 160));
myFrame.setSize(new Dimension(400, 160));
panel = new JPanel();
panel.setSize(400, 160);
ms1 = new JLabel();
paneScroll = new JScrollPane();
paneScroll.setPreferredSize(new Dimension(380,100));
paneScrollpanel = new JPanel();
paneScrollpanel.setPreferredSize(new Dimension(1600, 1600));
//if i add this line the whole paneScrollpanel disappears
//paneScrollpanel.setSize(1600, 1600);
String pl ="";
if (nf != 1) pl = "es";
String s1 = "We found " + nf + " flux"+pl+". Which one do you wanna choose ?";
ms1.setText(s1);
ArrayList<JRadioButton> Buttons = new ArrayList<JRadioButton>();
ArrayList<JLabel> Labels = new ArrayList<JLabel>();
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < nf; i++)
{
Buttons.add(new JRadioButton());
Labels.add(new JLabel("test"));
paneScrollpanel.add(Buttons.get(i));
paneScrollpanel.add(Labels.get(i));
group.add(Buttons.get(i));
}
Buttons.get(0).setSelected(true);
paneScroll.add(paneScrollpanel);
panel.add(ms1);
panel.add(paneScroll);
myFrame.add(panel);
myFrame.setVisible(true);
myFrame.setResizable(false);
}
}