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

📄 outlinedpanel.java

📁 一个功能比较全的JMail程序
💻 JAVA
字号:
package jws.awt;

// Copyright 1997, John Webster Small
// All rights Reserved

import java.awt.*;

public class OutlinedPanel extends WinPanel
{
  private String title;
  private int height, descent, titleWidth;
  private int top, left, vmargin, hmargin;
  private static final int titleHmargins = 3;

  /** Title inset from left. */
  public static int titleLeftOffset = 20;

  private void metrics()
  {
    FontMetrics fm = this.getFontMetrics(this.getFont());
    height = fm.getHeight();
    descent = fm.getMaxDescent();
    if (title == null)
      titleWidth = 0;
    else
      titleWidth = fm.stringWidth(title);
    top = height/3*2;
    Insets insets = super.getInsets();
    left = insets.left;
    vmargin = top+insets.bottom+1;
    hmargin = insets.left+insets.right+1;
  }

  /** @see java.awt.Component#addNotify */
  public void addNotify()
  {
    super.addNotify();
    metrics();
  }

  public void setFont(Font f)
  {
    super.setFont(f);
    metrics();
  }

  /** @see java.awt.Container#getInsets */
  public Insets getInsets()
  {
    Insets i = super.getInsets();
    i.top = height;
    i.top += descent;
    i.left++;
    i.right++;
    i.bottom++;
    return i;
  }

  /** @see java.awt.Component#getPreferredSize */
  public Dimension getPreferredSize()
  {
    Dimension d = super.getPreferredSize();
    int minWidth = (titleLeftOffset + titleHmargins) * 2 + titleWidth;
    if (d.width < minWidth)
      d.width = minWidth;
    d.height += height;
    d.height += descent;
    return d;
  }

  public Dimension getMinimumSize()
    { return getPreferredSize(); }

  /** Construct a Panel with a visible rectangle
    * outlining its extent.
    */
  public OutlinedPanel()
    { title = null; }

  /** Construct a Panel with a visible rectangle
    * outlining its extent.
    * @param title the title of this "group" panel
    */
  public OutlinedPanel(String title)
    { this.title = title; }

  /** @see java.awt.Component#paint */
  public void paint(Graphics g)
  {
    super.paint(g);
    Dimension d = getSize();
    g.drawRect(left,top,d.width-hmargin,d.height-vmargin);
    if (title != null)  {
      g.setColor(getBackground());
      g.drawLine(left+titleLeftOffset-titleHmargins,top,
        left+titleLeftOffset+titleWidth+titleHmargins,top);
      g.setColor(getForeground());
      g.drawString(title,titleLeftOffset,height);
    }
  }
}

⌨️ 快捷键说明

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