पर स्टैक करते समय शीर्ष पर ले जाएं। मेरे पास JPanel
है जो X_AXIS
दिशा में BoxLayout
का उपयोग करता है। समस्या मेरे पास है सबसे अच्छा एक छवि से दिखाया गया है: alt text http://www.freeimagehosting.net/uploads/fbffd71119.pngबॉक्सलेआउट को बाएं से दाएं
आप देख सकते हैं बाईं तरफ JPanel
बजाय केंद्रित कर दिया गया है शीर्ष पर गठबंधन। मैं उन्हें शीर्ष पर गठबंधन करना चाहता हूं और बाएं से दाएं स्टैक्ड करना चाहता हूं, मैं इस लेआउट मैनेजर के साथ इसे कैसे प्राप्त कर सकता हूं?
public GameSelectionPanel(){
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
setAlignmentY(TOP_ALIGNMENT);
setBorder(BorderFactory.createLineBorder(Color.black));
JPanel botSelectionPanel = new JPanel();
botSelectionPanel.setLayout(new BoxLayout(botSelectionPanel, BoxLayout.Y_AXIS));
botSelectionPanel.setBorder(BorderFactory.createLineBorder(Color.red));
JLabel command = new JLabel("Please select your opponent:");
ButtonGroup group = new ButtonGroup();
JRadioButton button1 = new JRadioButton("hello world");
JRadioButton button2 = new JRadioButton("hello world");
JRadioButton button3 = new JRadioButton("hello world");
JRadioButton button4 = new JRadioButton("hello world");
group.add(button1);
group.add(button2);
group.add(button3);
group.add(button4);
botSelectionPanel.add(command);
botSelectionPanel.add(button1);
botSelectionPanel.add(button2);
botSelectionPanel.add(button3);
botSelectionPanel.add(button4);
JPanel blindSelectionPanel = new JPanel();
blindSelectionPanel.setBorder(BorderFactory.createLineBorder(Color.yellow));
blindSelectionPanel.setLayout(new BoxLayout(blindSelectionPanel, BoxLayout.Y_AXIS));
JRadioButton button5 = new JRadioButton("hello world");
JRadioButton button6 = new JRadioButton("hello world");
ButtonGroup group2 = new ButtonGroup();
group2.add(button5);
group2.add(button6);
JLabel blindStructureQuestion = new JLabel("Please select the blind structure:");
blindSelectionPanel.add(blindStructureQuestion);
blindSelectionPanel.add(button5);
blindSelectionPanel.add(button6);
add(botSelectionPanel);
add(blindSelectionPanel);
setVisible(true);
}
वाह जीडीबी कक्षा के बारे में अच्छा दोस्त जोड़ें। हालांकि मैंने ग्रिडबैगकंट्रेन पूर्ण कन्स्ट्रक्टर का उपयोग शुरू किया था। मैंने पैरामीटर पदों को सीखा। लेकिन छोटे जीयूआई के लिए जीबीसी जाने का रास्ता है। बड़े जीयूआई के लिए मुझे लगता है कि एक लाइन पूर्ण ग्रिडबैग कॉन्स्ट्रेन कन्स्ट्रक्टर सबसे अच्छा समाधान है। – Timmos
ग्रिडबैगआउटआउट कन्स्ट्रक्टर में कोई इनपुट पैरामीटर नहीं है –
आपका नमूना धागा "एडब्ल्यूटी-इवेंट क्यूयू -0" java.lang.IllegalArgumentException में अपवाद देता है: अवैध एंकर मूल्य –