java.lang.Object
javax.swing.plaf.basic.BasicGraphicsUtils
方便的工具类。
-
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述static voiddrawBezel(Graphics g, int x, int y, int w, int h, boolean isPressed, boolean isDefault, Color shadow, Color darkShadow, Color highlight, Color lightHighlight) 绘制边框。static voiddrawDashedRect(Graphics g, int x, int y, int width, int height) 绘制虚线矩形。static voiddrawEtchedRect(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight) 绘制蚀刻矩形。static voiddrawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight) 绘制凹槽。static voiddrawLoweredBezel(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight) 绘制一个降低的边框。static voiddrawString(Graphics g, String text, int underlinedChar, int x, int y) 就像g.drawString一样,在位置 (x,y) 绘制一个带有图形g的字符串。static voiddrawString(JComponent c, Graphics2D g, String string, float x, float y) 使用提供的组件的文本属性和抗锯齿提示在指定位置绘制给定字符串。static voiddrawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y) 在位置 (x,y) 绘制带有图形g的字符串,就像g.drawString一样。static voiddrawStringUnderlineCharAt(JComponent c, Graphics2D g, String string, int underlinedIndex, float x, float y) 在给定字符下划线的指定位置绘制给定字符串。static StringgetClippedString(JComponent c, FontMetrics fm, String string, int availTextWidth) 将传入的字符串剪切到提供的空间。static Insets返回由drawEtchedRect()绘制的边框占用的空间量static Insets返回由drawGroove()绘制的边框占用的空间量static DimensiongetPreferredButtonSize(AbstractButton b, int textIconGap) 返回按钮的首选大小。static floatgetStringWidth(JComponent c, FontMetrics fm, String string) 使用提供的组件的文本属性和抗锯齿提示返回传入字符串的宽度。
-
构造方法详细信息
-
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
返回由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
返回由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
就像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
绘制虚线矩形。- 参数:
g-Graphics的实例x- X 坐标y- Y 坐标width- 矩形的宽度height- 矩形的高度
-
getPreferredButtonSize
返回按钮的首选大小。- 参数:
b-AbstractButton的实例textIconGap- 文本和图标之间的间隙- 返回:
- 按钮的首选大小
-
drawString
使用提供的组件的文本属性和抗锯齿提示在指定位置绘制给定字符串。没有为空字符串绘制任何内容。- 参数:
c- 将显示字符串的组件,可以为 nullg- 图形上下文,不能为空string- 要显示的字符串,可以为 nullx- 绘制文本的 x 坐标y- 绘制文本的 y 坐标- 抛出:
NullPointerException- 如果指定的g是null- 自从:
- 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- 将显示字符串的组件,可以为 nullg- 图形上下文,不能为空string- 要显示的字符串,可以为 nullunderlinedIndex- 要下划线的字符串中 char 值(Unicode 代码单元)的索引x- 绘制文本的 x 坐标y- 绘制文本的 y 坐标- 抛出:
NullPointerException- 如果指定的g是null- 自从:
- 9
- 参见:
-
getClippedString
public static String getClippedString(JComponent c, FontMetrics fm, String string, int availTextWidth) 将传入的字符串剪切到提供的空间。提供的组件用于查询文本属性和抗锯齿提示。如果提供的空间大于字符串宽度,则返回未更改的字符串。- 参数:
c- 组件,可能为空fm- 用于测量字符串宽度的 FontMetrics,必须从正确的字体和图形中获取。不得为空。string- 要剪辑的字符串,可以为 nullavailTextWidth- 可以绘制字符串的空间量- 返回:
-
适合所提供空间的剪切字符串,如果给定字符串参数为
null或为空,则为空字符串 - 抛出:
NullPointerException- 如果指定的fm是null- 自从:
- 9
- 参见:
-
getStringWidth
使用提供的组件的文本属性和抗锯齿提示返回传入字符串的宽度。如果传递的字符串是null,则返回零。- 参数:
c- 组件,可能为空fm- 用于测量高级字符串宽度的 FontMetrics,必须从正确的字体和图形中获取。不得为空。string- 获取其提前宽度的字符串,可能为空- 返回:
-
指定字符串的提前宽度,
null字符串返回零 - 抛出:
NullPointerException- 如果指定的fm是null- 自从:
- 9
-