मैं जावा में GRIDBAG लेआउट का उपयोग करGridbag लेआउट
public static void addComponentsToPane(Container pane) {
if (RIGHT_TO_LEFT) {
pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
JLabel label1,label2,label3,result,title;
JButton calculate_btn;
JTextField side1,side2,side3;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
if (shouldFill) {
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
}
title = new JLabel("Area of Triangle");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 2;
c.gridy = -1;
pane.add(title, c);
label1 = new JLabel("Side 1: ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 1;
c.gridy = 1;
pane.add(label1, c);
label2 = new JLabel("Side 2: ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 1;
c.gridy = 2;
pane.add(label2, c);
label3 = new JLabel("Side 3: ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 1;
c.gridy = 3;
pane.add(label3, c);
side1 = new JTextField(" ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 2;
c.gridy = 1;
pane.add(side1, c);
side2 = new JTextField("Side 3: ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 2;
c.gridy = 2;
pane.add(side2, c);
side3 = new JTextField("Side 3: ");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 2;
c.gridy = 3;
pane.add(side3, c);
calculate_btn = new JButton("Calculate");
//c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 30; //make this component tall
c.weightx = 0.5;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 5;
pane.add(calculate_btn, c);
result = new JLabel("Result displayed here");
if (shouldWeightX) {
c.weightx = 0.5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.gridx = 2;
c.gridy = 7;
pane.add(result, c);
}
तो उपरोक्त कोड मूल रूप से सिर्फ घटक है कि एक जीयूआई में जोड़ दिया जाएगा है इस लेआउट को लागू करने की कोशिश कर रहा हूँ, लेकिन मैं काफी हो रही है नहीं कर रहा हूँ कि मैं क्या समायोजन चाहते हैं, यह मैं क्या
प्राप्त करने के लिए कोशिश कर रहा हूँ है लेकिन यह है कि मैं क्या उपरोक्त कोड
के साथ हो रही है है
तो जब मैं ऊपर संकलन है जो मैं endup साथ, यह भी संभव है कि अगर मैं खिड़की, मैं खिड़की संपत्ति में से एक के साथ कुछ बूलियन अनुमान लगा रहा हूँ आकार बदलने के लिए उपयोगकर्ता चाहते हैं ..
'pane.setComponentOrientation (ComponentOrientation.RIGHT_TO_LEFT);' इस कोड को लाइन 'डैरिल Burke' या' camickr', विशेष रूप से उल्लेख किया स्विंग गुरुओं की दूसरी से कर रहा है मिल गया है इस मंच पर जीबीसी के बारे में कुछ उदाहरण, – mKorbel
जीबीसी केवल तभी काम करता है जब सभी कॉलम भर जाते हैं (अदृश्य जेकंपोनेंट्स का उपयोग करें), फिर आप किसी भी पंक्ति के लिए कॉलम का उपयोग कर सकते हैं :-), – mKorbel
+1 'ग्रिडबैगलाउट' – MadProgrammer