⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grouppanel.java

📁 此文档针对开发人员和测试人员。第二章对软件进行了全面的描述。第三章对接口进行了分析。第四章对软件实现的功能进行概述。第五章对软件后续开发实现提出的要求。第六章提出其他一些在软件开发过程中需要注意的问题
💻 JAVA
字号:
package com.ciash.common.gui;

import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.border.Border;
import java.awt.Component;
import java.awt.Insets;

/**
 * 该类简单封装了一个有边框绘制,并附加边框字的控件
 */

public class GroupPanel extends JPanel{

    private String groupName;

    public GroupPanel() {
        super();
        setBorder(new GroupBorder());
    }

    public GroupPanel(String tt){
        this();
        setGroupName(tt);
    }

    public void paint(Graphics g) {
        paintBack(g);
        paintChildren(g);
        paintBorder(g);
    }

    public void setGroupName(String tt) {
        this.groupName = tt;
    }

    public String getGroupName(){
        return this.groupName;
    }

    private void paintBack(Graphics g) {
        int width = getSize().width;
        int height = getSize().height;
        g.setColor(getBackground());
        g.fillRect(0, 0, width, height);
    }

    private class GroupBorder implements Border{

        public void paintBorder(Component component, Graphics g
            , int x, int y, int width, int height) {
            paintLine(g, width, height);
            paintString(g);
        }

        public Insets getBorderInsets(Component component) {
            if(groupName != null){
                return new Insets(10, 5, 5, 5);
            }
            else{
                return new Insets(5, 5, 5, 5);
            }

        }

        private void paintLine(Graphics g, int width, int height) {
            int d = 10;
            g.setColor(Color.DARK_GRAY);
            g.drawRect(d, d, width - d * 2, height - d * 2);
            d += 1;
            g.setColor(Color.WHITE);
            g.drawRect(d, d, width - d * 2, height - d * 2);
        }

        private void paintString(Graphics g) {
            if (groupName != null) {
                g.setColor(getBackground());
                g.fillRect(28, 5, 7 * groupName.getBytes().length, 18);
                g.setColor(Color.BLACK);
                g.drawString(groupName, 30, 15);
            }
        }

        public boolean isBorderOpaque() {
            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -