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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

java布局管理器的应用总结,GridBagLayout布局管理器的应用

發布時間:2024/2/28 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java布局管理器的应用总结,GridBagLayout布局管理器的应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

GridBagLayout布局管理器比較復雜,參數也比較多,參數的名字是

newGridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,

fill,insert,ipadx,ipady);每個參數均是按這樣的順序排列,關于參數的詳細介紹以后再寫,下面的例子用布局管理器實現了基本的功能

import java.awt.Dimension;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.Insets;

import java.awt.Toolkit;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

@SuppressWarnings("serial")

public class Teste3 extends JFrame{

private static JTextArea jTextArea;

private JButton jButton1;

private JButton jButton2;

private JButton jButton3;

public Teste3(){

GridBagLayout gridbag = new GridBagLayout();

this.setLayout(gridbag);

gridbag.setConstraints(getJtextArea(), new GridBagConstraints(0,0,3,2,1.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(100,100,30,100),0,0));

gridbag.setConstraints(getJButton1(), new GridBagConstraints(0,2,1,1,1.0,0.0,GridBagConstraints.SOUTH,GridBagConstraints.HORIZONTAL,new Insets(30,200,100,100),0,0));

gridbag.setConstraints(getJButton2(), new GridBagConstraints(1,2,1,1,1.0,0.0,GridBagConstraints.SOUTH,GridBagConstraints.HORIZONTAL,new Insets(30,100,100,100),0,0));

gridbag.setConstraints(getJButton3(), new GridBagConstraints(2,2,1,1,1.0,0.0,GridBagConstraints.SOUTH,GridBagConstraints.HORIZONTAL,new Insets(30,100,100,200),0,0));

this.add(getJtextArea());

this.add(getJButton1());

this.add(getJButton2());

this.add(getJButton3());

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

int screenWidth = (int) screenSize.getWidth(); //獲得屏幕的寬

int screenHight = (int) screenSize.getHeight();//獲得屏幕的高

this.setSize(screenWidth, screenHight);

this.setVisible(true);

}

private JTextArea getJtextArea(){

if(jTextArea == null){

jTextArea = new JTextArea();

}

return jTextArea;

}

private JButton getJButton1(){

if(jButton1 == null){

jButton1 = new JButton("jButton1");

}

return jButton1;

}

private JButton getJButton2(){

if(jButton2 == null){

jButton2 = new JButton("jButton2");

}

return jButton2;

}

private JButton getJButton3(){

if(jButton3 == null){

jButton3 = new JButton("jButton3");

}

return jButton3;

}

public static void main(String args[]){

new Teste3();

}

}

上面的代碼運行之后,窗口變化時頁面大小也會跟著變化,jTextArea窗口沒有加入滾動條,加入這兩行代碼后:

JScrollPane scroll = new JScrollPane(getJTextArea());

this.add(scroll);

jTextArea將變得不可見,正在調試中,也歡迎高手指教。

總結

以上是生活随笔為你收集整理的java布局管理器的应用总结,GridBagLayout布局管理器的应用的全部內容,希望文章能夠幫你解決所遇到的問題。

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