怎么样设置一个空白JLabel的高度??

lpj003 2004-06-14 12:57:12
JLabel a = new JLabel();
我想设置a的高度,该怎么办???
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyanggge 2004-06-14
  • 打赏
  • 举报
回复
我是来学习的
nwpulipeng 2004-06-14
  • 打赏
  • 举报
回复
我看了,默认的是(0,0)可以即使是这样它还是占着空间
RomandAccessFile 2004-06-14
  • 打赏
  • 举报
回复
JLabel l;l.setPreferredSize(new Dimension(100, 100));

其实还可以用一个方法,就是,

setLayout(null);
然后给每个个组件设定setBounds(100,100,100,100)前两个表示坐标,后两个表示Dimension
如果想知道默认,你可以用getP~()方法得到以后,输出不就可以看了吗,
北方的狼 2004-06-14
  • 打赏
  • 举报
回复
setPreferredSize()方法可以帮助你。
lpj003 2004-06-14
  • 打赏
  • 举报
回复
默认的是多少?
maowu 2004-06-14
  • 打赏
  • 举报
回复
JLabel a;
a.setPreferredSize(new Dimension(100, 100));
java编写的蜘蛛纸牌游戏代码 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Spider extends JFrame{ //整型变量,表示难度等级为:简单 public static final int EASY = 1; //整型变量,表示难度等级为:普通 public static final int NATURAL = 2; //整型变量,表示难度等级为:难 public static final int HARD = 3; //设定初始难度等级为简单 private int grade = Spider.EASY; private Container pane = null; //生成纸牌数组 private PKCard cards[] = new PKCard[104]; private JLabel clickLabel = null; private int c = 0;//牌的数量 private int n = 0; private int a = 0; private int finish = 0; Hashtable table = null; private JLabel groundLabel[] = null; public static void main(String[] args){ Spider spider = new Spider(); spider.setVisible(true); } /** **构造函数 */ public Spider(){ setTitle("蜘蛛牌"); //关闭窗口事件(使用 System exit(0)方法,直接关闭应用程序)setDefaultCloseOperation(3) setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); //设置框架的大小 setSize(1024, 742); //生成SpiderMenuBar对象,并放置在框架之上 setJMenuBar(new SpiderMenuBar(this)); pane = this.getContentPane();//getContentPane()获得JFrame的内容面板 //设置背景颜色 pane.setBackground(new Color(0, 112, 26)); //将布局管理器设置成为null,布局管理器用于设置游戏界面的仓储式大小及时间监听程序的引入布局 pane.setLayout(null); clickLabel = new JLabel(); //setBounds(),用来设置组件的大小和位置,首先要把上一阶的布局管理器设为null,两个是组件左上角在容器中的坐标,两个是宽度和高度 clickLabel.setBounds(883, 606, 121, 96); pane.add(clickLabel); //在布局管理器中设置对鼠标时间监听程序进行初始布局 clickLabel.addMouseListener(new MouseAdapter(){ public void mouseReleased(MouseEvent me){ if (c < 60){ Spider.this.deal(); } } }); //添加纸牌 this.initCards(); this.randomCards(); this.setCardsLocation(); groundLabel = new JLabel[10]; int x = 20; //对游戏的排放位置也要布局,纸牌需要摆放10列 for (int i = 0; i < 10; i++) { groundLabel[i] = new JLabel(); //setBorder()设置组件外围的边框,使用一个EmptyBorder对象能在组件周围留出空白 groundLabel[i].setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); //纸牌位置的大小也要用setBounds进行设置 groundLabel[i].setBounds(x, 25, 71, 96); x += 101; this.pane.add(groundLabel[i]);//添加到容器 } this.setVisible(true); this.deal(); this.addKeyListener(new KeyAdapter(){ class Show extends Thread{ public void run(){ Spider.this.showEnableOperator(); } } public void keyPressed(KeyEvent e){ if (finish != 8) if (e.getKeyCode() == KeyEvent.VK_D && c < 60){ Spider.this.deal(); } else if (e.getKeyCode() == KeyEvent.VK_M){ new Show().start(); } } }); } /** **开始新游戏 */ …………………… ……………… …………………… ^-^

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧