热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

JavaAwtSwing笔记之JComponentJLabel的setBorder(Border边框)用例

JComponentJLabel的setBorder前言用例2205262241前言setBorder(Border边框)实现自JComponentjava.awt.Insets


JComponent JLabel 的 setBorder

  • 前言
  • 用例 2205262241


前言

setBorder(Border 边框) 实现自JComponent
java.awt.Insets用于获取和包装Border的上左下右, 但不能设置
javax.swing.border.Border 是一个接口
javax.swing.border.AbstractBorder 是 implements Border, Serializable 的抽象类
具体实现基本在在javax.swing.border包中, 如TitledBorder , MatteBorder
可以new
也可以通过 BorderFactory 的静态方法获得


用例 2205262241

package jcomponent;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;public class SetBorder方法测试2205262241 {static Frame frame = new Frame("SetBorder方法测试2205262241");static JLabel jlb;static {frame.addWindowListener(new WindowAdapter() {@Override public void windowClosing(WindowEvent event) {frame.dispose();System.exit(0);}});frame.setBounds(100,50,1800,900);frame.setLayout(new GridLayout(0, 3, 5, 5));jlb = new JLabel("BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.red, Color.blue)"); frame.add(jlb);jlb.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.red, Color.blue));jlb = new JLabel("BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.red, Color.blue)"); frame.add(jlb);jlb.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.red, Color.blue));jlb = new JLabel("""

BorderFactory.createEmptyBorder(60, 200, 0, 0)

EmptyBorder不可见,但缩小了文字区域
可以用于移动文字
"""); frame.add(jlb);jlb.setBorder(BorderFactory.createEmptyBorder(60, 200, 0, 0)); jlb.setBackground(Color.yellow); jlb.setOpaque(true);jlb = new JLabel("BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.YELLOW, Color.GREEN)"); frame.add(jlb);jlb.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.YELLOW, Color.GREEN));jlb = new JLabel("BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.YELLOW, Color.GREEN)"); frame.add(jlb);jlb.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.YELLOW, Color.GREEN));jlb = new JLabel("BorderFactory.createLineBorder(Color.BLACK, 30, true)"); frame.add(jlb);jlb.setBorder(BorderFactory.createLineBorder(Color.BLACK, 30, true)); //true是圆角jlb = new JLabel("BorderFactory.createLineBorder(Color.BLACK, 30, false)"); frame.add(jlb);jlb.setBorder(BorderFactory.createLineBorder(Color.BLACK, 30, false));jlb = new JLabel("BorderFactory.createLoweredBevelBorder()"); frame.add(jlb);jlb.setBorder(BorderFactory.createLoweredBevelBorder());jlb = new JLabel("BorderFactory.createLoweredSoftBevelBorder()"); frame.add(jlb);jlb.setBorder(BorderFactory.createLoweredSoftBevelBorder());jlb = new JLabel("BorderFactory.createRaisedBevelBorder()"); frame.add(jlb);jlb.setBorder(BorderFactory.createRaisedBevelBorder());jlb = new JLabel("BorderFactory.createRaisedSoftBevelBorder()"); frame.add(jlb);jlb.setBorder(BorderFactory.createRaisedSoftBevelBorder());jlb = new JLabel("BorderFactory.createSoftBevelBorder(SoftBevelBorder.LOWERED, Color.ORANGE, Color.CYAN)"); frame.add(jlb);jlb.setBorder(BorderFactory.createSoftBevelBorder(SoftBevelBorder.LOWERED, Color.ORANGE, Color.CYAN));jlb = new JLabel("BorderFactory.createSoftBevelBorder(SoftBevelBorder.RAISED, Color.ORANGE, Color.CYAN)"); frame.add(jlb);jlb.setBorder(BorderFactory.createSoftBevelBorder(SoftBevelBorder.RAISED, Color.ORANGE, Color.CYAN));jlb = new JLabel("BorderFactory.createCompoundBorder()"); frame.add(jlb);jlb.setBorder(BorderFactory.createCompoundBorder());jlb = new JLabel("BorderFactory.createMatteBorder(10, 20, 30, 40, Color.BLACK)"); frame.add(jlb);jlb.setBorder(BorderFactory.createMatteBorder(10, 20, 30, 40, Color.BLACK));jlb = new JLabel("BorderFactory.createTitledBorder(\"如同Html的FieldSet\")"); frame.add(jlb);jlb.setBorder(BorderFactory.createTitledBorder("如同Html的FieldSet"));jlb = new JLabel("BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(10, 20, 30, 40, Color.BLACK) , \"如同Html的FieldSet\")"); frame.add(jlb);jlb.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(10, 20, 30, 40, Color.BLACK) , "如同Html的FieldSet"));jlb = new JLabel("""
BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(5, 10, 15, 20, Color.DARK_GRAY), "如同Html的FieldSet", TitledBorder.CENTER, TitledBorder.BOTTOM, new Font("宋体",Font.BOLD,20), Color.RED)
"""
); frame.add(jlb);jlb.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(5, 10, 15, 20, Color.DARK_GRAY), "如同Html的FieldSet", TitledBorder.CENTER, TitledBorder.BOTTOM, new Font("宋体",Font.BOLD,20), Color.RED));}public static void main(String...arguments) {frame.setVisible(true);}}

在这里插入图片描述


推荐阅读
author-avatar
幸福的xinwangnanfei_736
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有