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

📄 boxpanel.java

📁 < ProJavaProgrammingSecondEdition> 书中例程源码
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

public class BoxPanel extends JPanel {

  public void paintChildren(Graphics g) {
    super.paintChildren(g);
    Dimension size = getSize();
    LayoutManager manager = getLayout();
    if ((manager != null) && (manager instanceof BoxLayout)) {
      BoxLayout layout = (BoxLayout)manager;
      //  There's currently no accessor method that allows
      //  us to determine the orientation (vertical or
      //  horizontal) used by a BoxLayout, so we'll hard-code
      //  this class to assume vertical orientation
      boolean vertical = true;
      if (vertical) {
        int axis = (int)(layout.getLayoutAlignmentX(this) *
            size.width);
        g.fillRect(axis - 1, 0, 3, size.height);
      }
      else {
        int axis = (int)(layout.getLayoutAlignmentY(this) *
            size.height);
        g.fillRect(0, axis - 1, size.width, 3);
      }
    }
  }

}

⌨️ 快捷键说明

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