站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JavaTM 2 Platform Standard Edition 5.0 API 规范中文版

类 java.awt.Graphics 的使用 (Java 2 Platform SE 5.0) - JavaTM 2 Platform Standard Edition 5.0 API 规范中文版

JavaTM 2 Platform
Standard Ed. 5.0

类 java.awt.Graphics
的使用

使用 Graphics 的软件包
java.awt 包含用于创建用户界面和绘制图形图像的所有类。 
java.awt.image 提供创建和修改图像的各种类。 
java.awt.print 为通用的打印 API 提供类和接口。 
java.beans 包含与开发 beans 有关的类,即基于 JavaBeansTM 架构的组件。 
javax.swing 提供一组“轻量级”(全部是 Java 语言)组件,尽量让这些组件在所有平台上的工作方式都相同。 
javax.swing.border 提供围绕 Swing 组件绘制特殊边框的类和接口。 
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 
javax.swing.plaf 提供一个接口和许多抽象类,Swing 用它们来提供自己的可插入外观功能。 
javax.swing.plaf.basic 提供了根据基本外观构建的用户界面对象。 
javax.swing.plaf.metal 提供根据 Java 外观(曾经代称为 Metal)构建的用户界面对象,Java 外观是默认外观。 
javax.swing.plaf.multi 提供了组合两个或多个外观的用户界面对象。 
javax.swing.plaf.synth Synth 是一个可更换皮肤 (skinnable) 的外观,在其中可委托所有绘制。 
javax.swing.text 提供类 HTMLEditorKit 和创建 HTML 文本编辑器的支持类。 
javax.swing.text.html 提供类 HTMLEditorKit 和创建 HTML 文本编辑器的支持类。 
javax.swing.tree 提供处理 javax.swing.JTree 的类和接口。 
 

java.awtGraphics 的使用
 

java.awtGraphics 的子类
 class Graphics2D
          此 Graphics2D 类扩展了 Graphics 类,提供了对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制。
 

返回 Graphicsjava.awt 中的方法
abstract  Graphics Graphics.create()
          创建一个新的 Graphics 对象,它是此 Graphics 对象的副本。
 Graphics Graphics.create(int x, int y, int width, int height)
          基于此 Graphics 对象创建一个新的 Graphics 对象,但是使用新的转换和剪贴区域。
 Graphics Component.FlipBufferStrategy.getDrawGraphics()
           
 Graphics Component.BltBufferStrategy.getDrawGraphics()
           
 Graphics Component.getGraphics()
          为组件创建一个图形上下文。
abstract  Graphics Image.getGraphics()
          创建供绘制闭屏图像使用的图形上下文。
abstract  Graphics PrintJob.getGraphics()
          获取将绘制到下一页的 Graphics 对象。
 

参数类型为 Graphicsjava.awt 中的方法
 LineMetrics FontMetrics.getLineMetrics(char[] chars, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定字符数组的 LineMetrics 对象。
 LineMetrics FontMetrics.getLineMetrics(CharacterIterator ci, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 CharacterIteratorLineMetrics 对象。
 LineMetrics FontMetrics.getLineMetrics(String str, Graphics context)
          返回指定 Graphics 上下文中指定 StringLineMetrics 对象。
 LineMetrics FontMetrics.getLineMetrics(String str, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 StringLineMetrics 对象。
 Rectangle2D FontMetrics.getMaxCharBounds(Graphics context)
          返回指定 Graphics 上下文中具有最大边界的字符的边界。
 Rectangle2D FontMetrics.getStringBounds(char[] chars, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定字符数组的边界。
 Rectangle2D FontMetrics.getStringBounds(CharacterIterator ci, int beginIndex, int limit, Graphics context)
          返回用指定 Graphics 上下文中的指定 CharacterIterator 进行索引的字符的边界。
 Rectangle2D FontMetrics.getStringBounds(String str, Graphics context)
          返回指定 Graphics 上下文中指定 String 的边界。
 Rectangle2D FontMetrics.getStringBounds(String str, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 String 的边界。
 void Component.paint(Graphics g)
          绘制此组件。
 void Container.paint(Graphics g)
          绘制容器。
 void Canvas.paint(Graphics g)
          绘制这个 canvas。
 void Component.paintAll(Graphics g)
          绘制此组件及其所有子组件。
 void Container.paintComponents(Graphics g)
          绘制此容器中的每个组件。
 void Component.print(Graphics g)
          打印此组件。
 void Container.print(Graphics g)
          打印容器。
 void Component.printAll(Graphics g)
          打印此组件及其所有子组件。
 void Container.printComponents(Graphics g)
          打印此容器中的每个组件。
 void ScrollPane.printComponents(Graphics g)
          显示此滚动窗格中的组件。
 void Component.update(Graphics g)
          更新组件。
 void Container.update(Graphics g)
          更新容器。
 void Canvas.update(Graphics g)
          更新此 canvas。
 

java.awt.imageGraphics 的使用
 

返回 Graphicsjava.awt.image 中的方法
abstract  Graphics BufferStrategy.getDrawGraphics()
           
 Graphics BufferedImage.getGraphics()
          此方法返回 Graphics2D,但此处是出于向后兼容性的考虑。
 Graphics VolatileImage.getGraphics()
          此方法返回 Graphics2D,但此处是出于向后兼容性的考虑。
 

java.awt.printGraphics 的使用
 

参数类型为 Graphicsjava.awt.print 中的方法
 int Printable.print(Graphics graphics, PageFormat pageFormat, int pageIndex)
          将指定索引处的页面用指定格式打印到指定的 Graphics 上下文。
 

java.beansGraphics 的使用
 

参数类型为 Graphicsjava.beans 中的方法
 void PropertyEditor.paintValue(Graphics gfx, Rectangle box)
          在屏幕实际状态给定区域中绘制值的表示形式。
 void PropertyEditorSupport.paintValue(Graphics gfx, Rectangle box)
          在屏幕实际状态给定区域中绘制值的表示形式。
 

javax.swingGraphics 的使用
 

javax.swingGraphics 的子类
 class DebugGraphics
          支持图形调试的图形子类。
 

返回 Graphicsjavax.swing 中的方法
 Graphics DebugGraphics.create()
          重写 Graphics.create 来返回一个 DebugGraphics 对象。
 Graphics DebugGraphics.create(int x, int y, int width, int height)
          重写 Graphics.create 来返回一个 DebugGraphics 对象。
protected  Graphics JComponent.getComponentGraphics(Graphics g)
          返回用于绘制此组件的 graphics 对象。
 Graphics JComponent.getGraphics()
          返回此组件的图形上下文,该上下文允许您绘制组件。
 

参数类型为 Graphicsjavax.swing 中的方法
protected  Graphics JComponent.getComponentGraphics(Graphics g)
          返回用于绘制此组件的 graphics 对象。
 void JComponent.paint(Graphics g)
          由 Swing 调用,以绘制组件。
 void JLayeredPane.paint(Graphics g)
          在指定的图形上下文中绘制此 JLayeredPane。
 void CellRendererPane.paint(Graphics g)
          不应调用。
 void JViewport.paint(Graphics g)
          通过后备存储绘制图像,或者使用后备存储“位图传送”剩余图像来仅绘制最新暴露的部分,这具体取决于是否启用 backingStore
protected  void JComponent.paintBorder(Graphics g)
          绘制组件的边框。
protected  void AbstractButton.paintBorder(Graphics g)
          如果 BorderPainted 属性为 true 并且按钮有边框,则绘制该按钮边框。
protected  void JToolBar.paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制工具栏边框。
protected  void JMenuBar.paintBorder(Graphics g)
          如果 BorderPainted 属性为 true,则绘制菜单栏的边框。
protected  void JPopupMenu.paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制弹出菜单的边框。
protected  void JProgressBar.paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制进度条的边框。
protected  void JComponent.paintChildren(Graphics g)
          绘制此组件的子组件。
protected  void JSplitPane.paintChildren(Graphics g)
          通知超类后,UI 通过 finishedPaintingChildren 通知子类,同时绘制边框。
protected  void JComponent.paintComponent(Graphics g)
          如果 UI 委托为非 null,则调用该 UI 委托的 paint 方法。
protected  void JInternalFrame.paintComponent(Graphics g)
          重写此方法,以便在拖动内部窗体时允许进行优化的绘制。
static void SwingUtilities.paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
          在指定矩形中的任意图形 g 上绘制一个组件 c,指定该矩形的左上角位置和大小。
 void CellRendererPane.paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
          调用 this.paintComponent(g, c, p, x, y, w, h, false)。
 void CellRendererPane.paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate)
          在图形对象 g 上绘制一个单元格渲染器组件 c。
static void SwingUtilities.paintComponent(Graphics g, Component c, Container p, Rectangle r)
          在指定一个 Rectangle 对象的指定矩形中的任意图形 g 上绘制一个组件 c
 void CellRendererPane.paintComponent(Graphics g, Component c, Container p, Rectangle r)
          使用矩形的 x、y、width 和 height 字段的调用 this.paintComponent()。
 void Icon.paintIcon(Component c, Graphics g, int x, int y)
          在指定位置上绘制图标。
 void ImageIcon.paintIcon(Component c, Graphics g, int x, int y)
          绘制图标。
 void JComponent.print(Graphics g)
          调用此方法以打印组件。
 void JComponent.printAll(Graphics g)
          调用此方法以打印组件。
protected  void JComponent.printBorder(Graphics g)
          打印该组件的边框。
protected  void JComponent.printChildren(Graphics g)
          打印此组件的子组件。
protected  void JComponent.printComponent(Graphics g)
          在打印操作期间调用此方法。
 void JFrame.update(Graphics g)
          只是调用 paint(g)
 void JComponent.update(Graphics g)
          调用 paint
 void JDialog.update(Graphics g)
          调用 paint(g)
 void CellRendererPane.update(Graphics g)
          不应调用。
 void JWindow.update(Graphics g)
          调用 paint(g)
 void JApplet.update(Graphics g)
          只调用 paint(g)
 

参数类型为 Graphicsjavax.swing 中的构造方法
DebugGraphics(Graphics graphics)
          根据现有图形上下文构造一个调试图形上下文,该上下文支持减慢绘制。
DebugGraphics(Graphics graphics, JComponent component)
          根据现有图形上下文构造一个调试图形上下文,该上下文可以减慢指定组件的绘制。
 

javax.swing.borderGraphics 的使用
 

参数类型为 Graphicsjavax.swing.border 中的方法
 void Border.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按指定的位置和尺寸绘制指定组件的边框。
 void AbstractBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          此默认实现不执行绘制操作。
 void EmptyBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          默认情况下不执行绘制。
 void CompoundBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          绘制组合边框,方法是先按指定的位置和尺寸绘制外部边框,然后按照外部边框 insets 指定的位置和尺寸偏移量绘制内部边框。
 void MatteBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          绘制衬边边框。
 void LineBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按照指定的位置和尺寸为指定的组件绘制边框。
 void EtchedBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按照指定的位置和尺寸为指定的组件绘制边框
 void BevelBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按指定的位置和尺寸绘制指定组件的边框。
 void TitledBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按照指定的位置和尺寸为指定的组件绘制边框。
 void SoftBevelBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          按照指定的位置和尺寸绘制指定组件的边框。
protected  void BevelBorder.paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height)
           
protected  void BevelBorder.paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height)
           
 

javax.swing.colorchooserGraphics 的使用
 

参数类型为 Graphicsjavax.swing.colorchooser 中的方法
 void AbstractColorChooserPanel.paint(Graphics g)
          绘制面板。
 

javax.swing.plafGraphics 的使用
 

参数类型为 Graphicsjavax.swing.plaf 中的方法
abstract  void SplitPaneUI.finishedPaintingChildren(JSplitPane jc, Graphics g)
          在 JSplitPane 接收方提供外观来绘制其子组件之后传递消息。
 void ComponentUI.paint(Graphics g, JComponent c)
          绘制指定组件,使其适合外观。
 void BorderUIResource.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void IconUIResource.paintIcon(Component c, Graphics g, int x, int y)
           
 void ComponentUI.update(Graphics g, JComponent c)
          通知此 UI 委托开始绘制指定的组件。
 

javax.swing.plaf.basicGraphics 的使用
 

参数类型为 Graphicsjavax.swing.plaf.basic 中的方法
static void BasicGraphicsUtils.drawBezel(Graphics g, int x, int y, int w, int h, boolean isPressed, boolean isDefault, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
           
protected  void BasicTreeUI.drawCentered(Component c, Graphics graphics, Icon icon, int x, int y)
           
protected  void BasicTreeUI.drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
           
static void BasicGraphicsUtils.drawDashedRect(Graphics g, int x, int y, int width, int height)
           
protected  void BasicTreeUI.drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
           
static void BasicGraphicsUtils.drawEtchedRect(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
           
static void BasicGraphicsUtils.drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight)
           
static void BasicGraphicsUtils.drawLoweredBezel(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
           
static void BasicGraphicsUtils.drawString(Graphics g, String text, int underlinedChar, int x, int y)
          像 g.drawString 那样利用图形 g 在位置 (x,y) 绘制字符串。
static void BasicGraphicsUtils.drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
          像 g.drawString 那样利用图形 g 在位置 (x, y) 绘制字符串。
 void BasicSplitPaneUI.finishedPaintingChildren(JSplitPane jc, Graphics g)
          在 JSplitPane 接收者将为绘制其子级提供外观后传递消息。
protected  Point BasicProgressBarUI.getStringPlacement(Graphics g, String progressString, int x, int y, int width, int height)
          指定将绘制进度字符串的位置。
 void BasicToolBarUI.DragWindow.paint(Graphics g)
           
 void BasicArrowButton.paint(Graphics g)
           
 void BasicSplitPaneDivider.paint(Graphics g)
          绘制分隔符。
 void BasicInternalFrameTitlePane.SystemMenuBar.paint(Graphics g)
           
 void BasicLabelUI.paint(Graphics g, JComponent c)
          使用前景色绘制标签文本,如果标签不透明,则利用背景色绘制整个背景。
 void BasicButtonUI.paint(Graphics g, JComponent c)
           
 void BasicToggleButtonUI.paint(Graphics g, JComponent c)
           
 void BasicMenuItemUI.paint(Graphics g, JComponent c)
           
 void BasicSeparatorUI.paint(Graphics g, JComponent c)
           
 void BasicScrollBarUI.paint(Graphics g, JComponent c)
           
 void BasicComboBoxUI.paint(Graphics g, JComponent c)
           
 void BasicListUI.paint(Graphics g, JComponent c)
          绘制与 Graphics 对象 clipRect 相交的行。
 void BasicScrollPaneUI.paint(Graphics g, JComponent c)
           
 void BasicTextUI.paint(Graphics g, JComponent c)
          绘制界面。
 void BasicToolBarSeparatorUI.paint(Graphics g, JComponent c)
           
 void BasicTabbedPaneUI.paint(Graphics g, JComponent c)
           
 void BasicRadioButtonUI.paint(Graphics g, JComponent c)
          绘制单选按钮
 void BasicProgressBarUI.paint(Graphics g, JComponent c)
          将绘制委托给两种方法之一:paintDeterminate 和 paintIndeterminate。
 void BasicTableHeaderUI.paint(Graphics g, JComponent c)
           
 void BasicTableUI.paint(Graphics g, JComponent c)
          绘制用 installUI() 设置的 table 实例的表示形式。
 void BasicTreeUI.paint(Graphics g, JComponent c)
           
 void BasicSplitPaneUI.paint(Graphics g, JComponent jc)
          传递消息以绘制外观。
 void BasicSliderUI.paint(Graphics g, JComponent c)
           
 void BasicDesktopPaneUI.paint(Graphics g, JComponent c)
           
 void BasicToolTipUI.paint(Graphics g, JComponent c)
           
 void BasicPopupMenuSeparatorUI.paint(Graphics g, JComponent c)
           
protected  void BasicTextUI.paintBackground(Graphics g)
          绘制视图的背景。
protected  void BasicMenuItemUI.paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
          绘制菜单项的背景。
 void BasicBorders.RolloverButtonBorder.paintBorder(Component c, Graphics g, int x, int y, int w, int h)
           
 void BasicBorders.ButtonBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void BasicBorders.ToggleButtonBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void BasicBorders.RadioButtonBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void BasicBorders.MenuBarBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void BasicBorders.FieldBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
 void BasicBorders.SplitPaneBorder.paintBorder(Component c, Graphics g, int x, int y, int width, int height)
           
protected  void BasicButtonUI.paintButtonPressed(Graphics g, AbstractButton b)
           
protected  void BasicListUI.paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer, ListModel dataModel, ListSelectionModel selModel, int leadIndex)
          绘制一个 List 单元格:计算相关状态,获取“橡皮图章”单元格渲染器组件,然后使用 CellRendererPane 来绘制它。
 void BasicInternalFrameTitlePane.paintComponent(Graphics g)
           
protected  void BasicTabbedPaneUI.paintContentBorder(Graphics g, int tabPlacement, int selectedIndex)
           
protected  void BasicTabbedPaneUI.paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
           
protected  void BasicTabbedPaneUI.paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
           
protected  void BasicTabbedPaneUI.paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
           
protected  void BasicTabbedPaneUI.paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
           
 void BasicComboBoxUI.paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
          绘制当前所选项。
 void BasicComboBoxUI.paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
          绘制当前所选项的背景。
protected  void BasicScrollBarUI.paintDecreaseHighlight(Graphics g)
           
protected  void BasicProgressBarUI.paintDeterminate(Graphics g, JComponent c)
          对几乎所有线性、确定进度条都能正确执行操作的多用途绘制方法。
protected  void BasicLabelUI.paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
          利用 background.lighter() 将 clippedText 绘制在 textX、textY 处,然后利用 background.darker() 向右下移动一个像素。
protected  void BasicToolBarUI.paintDragWindow(Graphics g)
          绘制用于拖动的窗口的内容。
protected  void BasicLabelUI.paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY)
          利用标签的前景色将 clippedText 绘制在 textX、textY 处。
protected  void BasicTreeUI.paintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
          绘制 row 的展开(切换)部分。
 void BasicSliderUI.paintFocus(Graphics g)
           
protected  void BasicButtonUI.paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect)
           
protected  void BasicRadioButtonUI.paintFocus(Graphics g, Rectangle textRect, Dimension size)
           
protected  void BasicTabbedPaneUI.paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)
           
protected  void BasicSliderUI.paintHorizontalLabel(Graphics g, int value, Component label)
          为标签表中的每个标签调用此方法。
protected  void BasicTreeUI.paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)
          绘制水平线。
protected  void BasicTreeUI.paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
          绘制支路 (leg) 的水平部分。
protected  void BasicToggleButtonUI.paintIcon(Graphics g, AbstractButton b, Rectangle iconRect)
           
protected  void BasicTabbedPaneUI.paintIcon(Graphics g, int tabPlacement, int tabIndex, Icon icon, Rectangle iconRect, boolean isSelected)
           
protected  void BasicButtonUI.paintIcon(Graphics g, JComponent c, Rectangle iconRect)
           
protected  void BasicScrollBarUI.paintIncreaseHighlight(Graphics g)
           
protected  void BasicProgressBarUI.paintIndeterminate(Graphics g, JComponent c)
          对所有线性跳动框进度条都能正确执行操作的多用途绘制方法。
 void BasicSliderUI.paintLabels(Graphics g)
           
protected  void BasicSliderUI.paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
           
protected  void BasicSliderUI.paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
           
protected  void BasicMenuItemUI.paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background,