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

📄 multilinelabel.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/* HEDAER */

package com.sshtools.ui.swing;

import java.util.StringTokenizer;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Swing component that takes a string, splits it up into lines based on the
 * newline character and displays each line.
 *
 * @author $Author: lee $
 * @version $Revision: 1.3 $
 */

public class MultilineLabel
    extends JPanel {

  //  Private instance variables

  private GridBagConstraints constraints;

  private String text;

  /**
   * Creates a new MultilineLabel object.
   */

  public MultilineLabel() {

    this("");

  }

  /**
   * Creates a new MultilineLabel object.
   *
   * @param text
   */

  public MultilineLabel(String text) {

    super(new GridBagLayout());

    constraints = new GridBagConstraints();

    constraints.anchor = GridBagConstraints.NORTHWEST;

    constraints.fill = GridBagConstraints.NONE;

    setText(text);

  }

  /**
   * Set the font
   *
   * @param f font
   */

  public void setFont(Font f) {

    super.setFont(f);

    for (int i = 0; i < getComponentCount(); i++) {

      getComponent(i).setFont(f);

    }

  }

  /**
   * Set the font
   *
   * @param text
   */

  public void setText(String text) {

    this.text = text;

    removeAll();

    StringTokenizer tok = new StringTokenizer(text, "\n");

    constraints.weighty = 0.0;

    constraints.weightx = 1.0;

    while (tok.hasMoreTokens()) {

      String t = tok.nextToken();

      if (!tok.hasMoreTokens()) {

        constraints.weighty = 1.0;

      }

      UIUtil.jGridBagAdd(this, new JLabel(t), constraints,

                         GridBagConstraints.REMAINDER);

    }

    revalidate();

    repaint();

  }

  /**
   * Get the text
   *
   * @return text
   */

  public String getText() {

    return text;

  }

}

⌨️ 快捷键说明

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