「java盒式布局例题」java箱式布局

博主:adminadmin 2023-01-27 15:00:11 363

本篇文章给大家谈谈java盒式布局例题,以及java箱式布局对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

我们java老师让我们把下面这道例题改一下,使两个按钮放在同一个位置东南西北中任意一个按钮空出一个位置

import java.awt.*;

public class BorderLayoutDemo {

public static void main(String args[])

{

Button north=new Button( "north");

Button east=new Button( "east");

Button west=new Button( "west");

Button south=new Button( "south");

Button center=new Button( "center");

Frame win=new Frame("border Style");

JPanel jp=new JPanel();//添加到JFram边界布局的任何位置,它的默认布局是流布局

//你们老师可能想你们了解JFrame嵌套JPanel面板

win.setLayout(new BorderLayout());

//例如我想把北部按钮和中部按钮放一起

win.add(jp,BorderLayout.CENTER);

jp.add(center);

jp.add(north)

win.add("South",south);

win.add("East",east);

win.add("West",west);

win.setSize(200,200);

win.setVisible(true);

}

java布局的问题

你可以采用盒式布局的嵌套使用,两个横盒子,然后添加到竖盒子,

还有就是当你设置了布局后在对该组件调用setSize()就没有作用了

java学习交流群 194252842

java box怎么用

Box一般用的最多的就是 Box createHorizontalBox() 1 Box createVerticalBox() 2 Component createHorizontalStrut(int width) 3 Component createVerticalStrut(int height) 4 Component createHorizontalGlue() 5 Component createVerticalGlue() 6 Box用的是BoxLayout布局, 其中12连用可以完成一些盒式布局,最常见的就是登陆/注册界面了。 其中3456都是一些不可见的组件,辅助支持组件布局,能使界面较美观。 顺便给一个例子: import javax.swing.*; import java.awt.*; import javax.swing.border.*; public class Example10_5{ public static void main(String args[]){ new WindowBox(); } } class WindowBox extends JFrame{ Box baseBox,boxV1,boxV2; WindowBox(){ boxV1=Box.createVerticalBox(); boxV1.add(new JLabel("输入您的姓名")); boxV1.add(Box.createVerticalStrut(8)); boxV1.add(new JLabel("输入email")); boxV1.add(Box.createVerticalStrut(8)); boxV1.add(new JLabel("输入您的职业")); boxV2=Box.createVerticalBox(); boxV2.add(new JTextField(16)); boxV2.add(Box.createVerticalStrut(8)); boxV2.add(new JTextField(16)); boxV2.add(Box.createVerticalStrut(8)); boxV2.add(new JTextField(16)); baseBox=Box.createHorizontalBox(); baseBox.add(boxV1); baseBox.add(Box.createHorizontalStrut(10)); baseBox.add(boxV2); setLayout(new FlowLayout()); add(baseBox); validate(); setBounds(120,125,200,200); setVisible(true); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } }

java新手请问swing的一个小问题~~

=。= 是不是没有

add(boxV4);

给你看我的程序:

import java.awt.*;

import javax.swing.*;

class test extends JFrame

{

test()

{

setLayout(new FlowLayout());

setBounds(100,100,300,100);

Box boxV4=Box.createHorizontalBox();

ButtonGroup cg=new ButtonGroup();

JRadioButton b1=new JRadioButton("小学");

JRadioButton b2=new JRadioButton("中学");

JRadioButton b3=new JRadioButton("大学");

JLabel lb1=new JLabel("学历:");

boxV4.add(lb1);cg.add(b1);cg.add(b2);cg.add(b3);

boxV4.add(b1);

boxV4.add(b2);

boxV4.add(b3);

add(boxV4);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

validate();

}

public static void main(String[] args)

{

new test();

}

}

关于java盒式布局例题和java箱式布局的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。