日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java gridbag_java – 调整Gridbag布局

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

我試圖在

java中使用GRIDBAG布局實現(xiàn)此布局

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的組件,但我不是很想得到我想要的,這就是我想要實現(xiàn)的

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

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

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。