swing 编程的一些总结

来源:互联网 发布:24周胎儿四维彩超数据 编辑:程序博客网 时间:2024/05/23 13:00

很浅显的一些使用,若有错误之处,敬请见谅,望指正。好读书不求甚解!

1. 关于 javax.swing.Timer

它的开启使用 start方法,暂停使用 stop,唤醒使用 restart方法。repeats方法,传入false之后 ,再运行一次,则不再运行,即使使用restart也不能唤醒!


2. CompoundBorder的使用

 CompoundBorder cb = new CompoundBorder( new EtechedBorder(), new EmptyBorder( 6, 6, 6, 6 ) );

panel.setBorder( cb );


3. JPanel 的paint方法应该注意的东西

g.clearRect( 0, 0 ,width, height )会将这块区域变成白色,若想使用自定义的背景色消除区域,应该使用 super.paint( g );


4. swing的定位,

swing的定位的基本思想是 边框布局中套边框布局或者是流布局或者盒布局。基本使用这种方法。(比较简单,CoreJava中有其它方法,感觉比较麻烦)


5. 若在 想使JFrame中添加的 panel 中添加一个新的panel,并让新的 panel的 repaint方法有效,应该如下所示的做法:

frame.getContentPane().add( contentPanel );contentPanel.add( controlPanel );contentPanel.add( blockPanel );/* * 若使用 frame.add( contentPanel ) * contentPanel.add( controlPanel ) * contentPanel.add( blockPanel ) * * blockPanel.repaint();//无效. * */

6. 撤销 JButton 点击后 文字周围出现边框
    beginButton.setFocusPainted( false );

7. 取消 JFrame 的window下的外围装饰,并设置简要的格式:

this.setUndecorated( true );this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

8. 新字体

new Font( "字体名称",字体样式,字体大小 );


9. JLabel中改变 字体颜色:

timeLabel.setForeground( Color );




原创粉丝点击