模块 java.desktop

类 BasicGraphicsUtils

java.lang.Object
javax.swing.plaf.basic.BasicGraphicsUtils

public class BasicGraphicsUtils extends Object
方便的工具类。
  • 构造方法详细信息

    • BasicGraphicsUtils

      public BasicGraphicsUtils()
      构造一个 BasicGraphicsUtils
  • 方法详情

    • drawEtchedRect

      public static void drawEtchedRect(Graphics  g, int x, int y, int w, int h, Color  shadow, Color  darkShadow, Color  highlight, Color  lightHighlight)
      绘制蚀刻矩形。
      参数:
      g - Graphics 的实例
      x - X 坐标
      y - Y 坐标
      w - 宽度
      h - 身高
      shadow - 阴影颜色
      darkShadow - 深色阴影
      highlight - 颜色突出显示
      lightHighlight - 一种颜色的光突出显示
    • getEtchedInsets

      public static Insets  getEtchedInsets()
      返回由 drawEtchedRect() 绘制的边框占用的空间量
      返回:
      蚀刻矩形的insets
    • drawGroove

      public static void drawGroove(Graphics  g, int x, int y, int w, int h, Color  shadow, Color  highlight)
      绘制凹槽。
      参数:
      g - Graphics 的实例
      x - X 坐标
      y - Y 坐标
      w - 宽度
      h - 身高
      shadow - 阴影颜色
      highlight - 颜色突出显示
    • getGrooveInsets

      public static Insets  getGrooveInsets()
      返回由 drawGroove() 绘制的边框占用的空间量
      返回:
      凹槽边框的插入
    • drawBezel

      public static void drawBezel(Graphics  g, int x, int y, int w, int h, boolean isPressed, boolean isDefault, Color  shadow, Color  darkShadow, Color  highlight, Color  lightHighlight)
      绘制边框。
      参数:
      g - Graphics 的实例
      x - X 坐标
      y - Y 坐标
      w - 宽度
      h - 身高
      isPressed - 组件是否按下
      isDefault - 是默认绘图
      shadow - 阴影颜色
      darkShadow - 深色阴影
      highlight - 颜色突出显示
      lightHighlight - 一种颜色的光突出显示
    • drawLoweredBezel

      public static void drawLoweredBezel(Graphics  g, int x, int y, int w, int h, Color  shadow, Color  darkShadow, Color  highlight, Color  lightHighlight)
      绘制一个降低的边框。
      参数:
      g - Graphics 的实例
      x - X 坐标
      y - Y 坐标
      w - 宽度
      h - 身高
      shadow - 阴影颜色
      darkShadow - 深色阴影
      highlight - 颜色突出显示
      lightHighlight - 一种颜色的光突出显示
    • drawString

      public static void drawString(Graphics  g, String  text, int underlinedChar, int x, int y)
      就像 g.drawString 一样,在位置 (x,y) 绘制一个带有图形 g 的字符串。文本中第一次出现的 underlineChar 将带有下划线。匹配算法不区分大小写。
      参数:
      g - Graphics 的实例
      text - 一段文字
      underlinedChar - 带下划线的字符
      x - X 坐标
      y - Y 坐标
    • drawStringUnderlineCharAt

      public static void drawStringUnderlineCharAt(Graphics  g, String  text, int underlinedIndex, int x, int y)
      在位置 (x, y) 绘制带有图形 g 的字符串,就像 g.drawString 一样。文本中索引 underlinedIndex 处的字符将带有下划线。如果 index 超出了 text 的范围(包括 < 0),则不会有任何下划线。
      参数:
      g - 用于绘制的图形
      text - 要绘制的字符串
      underlinedIndex - 文本中要加下划线的字符索引
      x - 绘制的 x 坐标
      y - 绘制的 y 坐标
      自从:
      1.4
    • drawDashedRect

      public static void drawDashedRect(Graphics  g, int x, int y, int width, int height)
      绘制虚线矩形。
      参数:
      g - Graphics 的实例
      x - X 坐标
      y - Y 坐标
      width - 矩形的宽度
      height - 矩形的高度
    • getPreferredButtonSize

      public static Dimension  getPreferredButtonSize(AbstractButton  b, int textIconGap)
      返回按钮的首选大小。
      参数:
      b - AbstractButton 的实例
      textIconGap - 文本和图标之间的间隙
      返回:
      按钮的首选大小
    • drawString

      public static void drawString(JComponent  c, Graphics2D  g, String  string, float x, float y)
      使用提供的组件的文本属性和抗锯齿提示在指定位置绘制给定字符串。没有为空字符串绘制任何内容。
      参数:
      c - 将显示字符串的组件,可以为 null
      g - 图形上下文,不能为空
      string - 要显示的字符串,可以为 null
      x - 绘制文本的 x 坐标
      y - 绘制文本的 y 坐标
      抛出:
      NullPointerException - 如果指定的 gnull
      自从:
      9
    • drawStringUnderlineCharAt

      public static void drawStringUnderlineCharAt(JComponent  c, Graphics2D  g, String  string, int underlinedIndex, float x, float y)
      在给定字符下划线的指定位置绘制给定字符串。提供的组件用于查询文本属性和抗锯齿提示。

      underlinedIndex 参数指向给定字符串中的一个字符值(Unicode 代码单元)。如果在带下划线的索引处指定的 char 值在高代理项范围内,而在以下索引处指定的 char 值在低代理项范围内,则与该代理项对对应的增补字符带有下划线。

      如果索引为负或大于字符串长度 (index < 0 || index >= string.length()),或者给定索引处指定的 char 值在低代理项范围内,则不会为任何字符添加下划线。

      参数:
      c - 将显示字符串的组件,可以为 null
      g - 图形上下文,不能为空
      string - 要显示的字符串,可以为 null
      underlinedIndex - 要下划线的字符串中 char 值(Unicode 代码单元)的索引
      x - 绘制文本的 x 坐标
      y - 绘制文本的 y 坐标
      抛出:
      NullPointerException - 如果指定的 gnull
      自从:
      9
      参见:
    • getClippedString

      public static String  getClippedString(JComponent  c, FontMetrics  fm, String  string, int availTextWidth)
      将传入的字符串剪切到提供的空间。提供的组件用于查询文本属性和抗锯齿提示。如果提供的空间大于字符串宽度,则返回未更改的字符串。
      参数:
      c - 组件,可能为空
      fm - 用于测量字符串宽度的 FontMetrics,必须从正确的字体和图形中获取。不得为空。
      string - 要剪辑的字符串,可以为 null
      availTextWidth - 可以绘制字符串的空间量
      返回:
      适合所提供空间的剪切字符串,如果给定字符串参数为 null 或为空,则为空字符串
      抛出:
      NullPointerException - 如果指定的 fmnull
      自从:
      9
      参见:
    • getStringWidth

      public static float getStringWidth(JComponent  c, FontMetrics  fm, String  string)
      使用提供的组件的文本属性和抗锯齿提示返回传入字符串的宽度。如果传递的字符串是 null ,则返回零。
      参数:
      c - 组件,可能为空
      fm - 用于测量高级字符串宽度的 FontMetrics,必须从正确的字体和图形中获取。不得为空。
      string - 获取其提前宽度的字符串,可能为空
      返回:
      指定字符串的提前宽度,null 字符串返回零
      抛出:
      NullPointerException - 如果指定的 fmnull
      自从:
      9