日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java gridbag_java – 调整Gridbag布局

發布時間:2025/3/20 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java gridbag_java – 调整Gridbag布局 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖在

java中使用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);

}

所以上面的代碼基本上只是將添加到GUI的組件,但我不是很想得到我想要的,這就是我想要實現的

但這是我用上面的代碼得到的

因此,當我編譯上面是我最終的,也是如果可能我不希望用戶調整窗口大小,我猜一些布爾與窗口屬性之一..

總結

以上是生活随笔為你收集整理的java gridbag_java – 调整Gridbag布局的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。