java網(wǎng)格布局代碼,java 網(wǎng)格包布局

java中網(wǎng)格包布局代碼哪里出錯(cuò)?

寫(xiě)的時(shí)候仔細(xì)點(diǎn),setLyaout方法里面有錯(cuò)

10多年的海林網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣的優(yōu)勢(shì)是能夠根據(jù)用戶(hù)設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整海林建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“海林網(wǎng)站設(shè)計(jì)”,“海林網(wǎng)站推廣”以來(lái),每個(gè)客戶(hù)項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

lbUser=new JLabel("用戶(hù)名");

gbLayout.setConstraints(tfUser,constraints);

container.add(tfUser);

你這里把 lbUser 指向了對(duì)象,此是的tfUser還沒(méi)有,而你加的時(shí)候確是加的tfUser, 你把 tfUser改過(guò)來(lái)就好了

import javax.swing.*;

import java.awt.*;

public class GridBagLayoutDemo extends JFrame {

private GridBagLayout gbLayout = new GridBagLayout();

private GridBagConstraints constraints = new GridBagConstraints();

private JLabel lbUser, lbPassword;

private JTextField tfUser, tfPassword;

private JButton btnLog;

private Container container;

public GridBagLayoutDemo() {

super("網(wǎng)格包布局");

this.setSize(300, 200);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private void setConstraints(GridBagConstraints gbc, int row, int column,

int numRows, int numColumns, int Weightx, int Weighty) {

gbc.gridx = row;

gbc.gridy = column;

gbc.gridwidth = numRows;

gbc.gridheight = numColumns;

gbc.weightx = Weightx;

gbc.weighty = Weighty;

}

public void setLyaout() {

container = this.getContentPane();

container.setLayout(gbLayout);

// 添加用戶(hù)名標(biāo)簽

constraints.fill = GridBagConstraints.NONE;

constraints.anchor = GridBagConstraints.CENTER;

setConstraints(constraints, 0, 0, 1, 1, 0, 0);

lbUser = new JLabel("用戶(hù)名");

gbLayout.setConstraints(lbUser, constraints);

container.add(lbUser);

// 添加用戶(hù)名文本框

constraints.fill = GridBagConstraints.HORIZONTAL;

setConstraints(constraints, 1, 0, 1, 1, 100, 100);

tfUser = new JTextField();

gbLayout.setConstraints(tfUser, constraints);

container.add(tfUser);

// 添加密碼標(biāo)簽

constraints.fill = GridBagConstraints.NONE;

setConstraints(constraints, 0, 1, 1, 1, 0, 0);

lbPassword = new JLabel("密碼");

gbLayout.setConstraints(lbPassword, constraints);

container.add(lbPassword);

// 添加密碼文本框

constraints.fill = GridBagConstraints.HORIZONTAL;

setConstraints(constraints, 1, 1, 1, 1, 100, 100);

tfPassword = new JTextField();

gbLayout.setConstraints(tfPassword, constraints);

container.add(tfPassword);

// 添加登錄按鈕

constraints.fill = GridBagConstraints.CENTER;

setConstraints(constraints, 0, 2, 2, 1, 0, 0);

btnLog = new JButton("登錄");

gbLayout.setConstraints(btnLog, constraints);

container.add(btnLog);

}

public static void main(String[] args) {

GridBagLayoutDemo frame = new GridBagLayoutDemo();

frame.setLyaout();

frame.show();

}

}

Java網(wǎng)格包布局,組件垂直間距怎么調(diào)

GridBagLayout里的各種設(shè)置都必須通過(guò)GridBagConstraints,因此當(dāng)我們將GridBagConstraints的參數(shù)都設(shè)置

好了之后,必須new一個(gè)GridBagConstraints的對(duì)象出來(lái),以便GridBagLayout使用。

參數(shù)說(shuō)明:

gridx,gridy:設(shè)置組件的位置,gridx設(shè)置為GridBagConstraints.RELATIVE代表此組件位于之前所加入組件的右邊。

若將gridy設(shè)置為GridBagConstraints.RELATIVE代表此組件位于以前所加入組件的下面。建議定義出gridx,gridy的

位置,以便以后維護(hù)程序。表示放在幾行幾列,gridx=0,gridy=0時(shí)放在0行0列。

gridwidth,gridheight:用來(lái)設(shè)置組件所占的單位長(zhǎng)度與高度,默認(rèn)值皆為1。你可以使用GridBagConstraints.REMAINDER常量,代表此組件為此行或此列的最后一個(gè)組件,而且會(huì)占據(jù)所有剩余的空間。

weightx,weighty:用來(lái)設(shè)置窗口變大時(shí),各組件跟著變大的比例,當(dāng)數(shù)字越大,表示組件能得到更多的空間,默認(rèn)值皆為0。

anchor:當(dāng)組件空間大于組件本身時(shí),要將組件置于何處,有CENTER(默認(rèn)值)、NORTH、NORTHEAST、EAST、SOUTHEAST、 WEST、NORTHWEST可供選擇。

insets:設(shè)置組件之間彼此的間距,它有四個(gè)參數(shù),分別是上,左,下,右,默認(rèn)為(0,0,0,0).

ipadx,ipady:設(shè)置組件內(nèi)的間距,默認(rèn)值為0。

安卓網(wǎng)格布局如何用java代碼實(shí)現(xiàn)跨多行跨多列

之前有人做過(guò)用Table來(lái)實(shí)現(xiàn)一個(gè)表單的效果,其中也有跨多行和多列,是用純java代碼實(shí)現(xiàn)的,沒(méi)有使用XML。用網(wǎng)格布局GridView也可以實(shí)現(xiàn)

新聞名稱(chēng):java網(wǎng)格布局代碼,java 網(wǎng)格包布局
轉(zhuǎn)載注明:http://muchs.cn/article34/hssdse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)網(wǎng)站收錄、自適應(yīng)網(wǎng)站、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)