码迷,mamicode.com
首页 > Windows程序 > 详细

swing、JFrame、JScrollPane、JTabbedPane、JEditorPane

时间:2014-09-09 20:02:39      阅读:935      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   java   ar   strong   cti   

 

swing、JFrame、JButton、JScrollPane、JLabel、JTabbedPane、JEditorPane总结


1、JButton内边距(去掉按钮里的空白):setMargin
2、JLabel背景不透明:setOpaque
3、JLabel/JTextField内容居中:setHorizontalAlignment
4、字体:new Font("微软雅黑",Font.BOLD,16);
5、设置JFrame屏幕居中:先setSize,再setLocationRelativeTo(null);
6、鼠标指针(手型):setCursor(new Cursor(Cursor.HAND_CURSOR));
7、JFrame去掉装饰:setUndecorated
8、添加图片:Image img = ImageIO.read(new File("src/image/llj.jpg"));
   g.drawImage(img, left, top, width, height, fm);
   重写paint:new ImageIcon("src/image/llj.jpg").paintIcon(fm, g, x, y);
   fm.getGraphics()与fm.getContentPane().getGraphics()是有差别的
9、pane.setPreferredSize(new Dimension(0, top(0)));// 宽度设置为0时默认填满宽度
   JSrollPane:new JSrollPane(pane);
   pane要setPreferredSize才能设置在JSrollPane里的大小。长度(宽度)动态设置效果更好
10、JTabbedPane:JTabbedPane tp = new JTabbedPane(JTabbedPane.TOP);// 标题栏在上面
   tp.add("标题",new JPanel());
     JTabbedPane页签改变事件监听:addChangeListener;获得当前选定页签:getSelectedComponent
11、用JTextArea生成一个JScrollPane,就成了带滚动条的文本区域。
   JTextArea:setLineWrap(true);//自动换行
       setWrapStyleWord(true); //换行不断字
       JPanel里设置layout为GridLayout()或BorderLayout会默认填满
12、JEditorPane,HTML-Hyperlink,设置setEditorable(false);才有点击超链接的效果
   new JEditorPane("text/html",String html);
   HyperlinkListener
   e.getEventType() == HyperlinkEvent.EventType.ACTIVATED

版主的个人网站:http://liaolongjun.duapp.com/

 

swing、JFrame、JScrollPane、JTabbedPane、JEditorPane

标签:style   http   color   os   io   java   ar   strong   cti   

原文地址:http://www.cnblogs.com/liaolongjun/p/3963214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!