In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what is the use of SwingUtilities in Swing, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Utility of Swing
Swing provides many utilities for use within Swing components, and the SwingUtilities class is one of them. It provides many methods related to computing, transformation, access control, layout and so on. These methods have been widely used in a variety of Swing components. Of course, we can also apply it to our own programs.
Let's take a look at one of these practical functions.
(1) conversion method
◆ MouseEvent convertMouseEvent (Component source, MouseEvent ourceEvent, Component destination)
Converts a mouse event from one component to another.
◆ Point convertPoint (Component source, int x, int y, Component estination)
◆ Point convertPoint (Component source, Point aPoint, Component destination)
Converts the coordinates of a point on one component to a coordinate point on another.
◆ void convertPointFromScreen (Point p, Component c)
Convert a dusk coordinate point into a component coordinate point.
◆ void convertPointToScreen (Point p, omponent c)
Converts coordinate points on a component to screen coordinates.
◆ Rectangle convertRectangle (Component source, Rectangle aRectangle, Component destination)
Converts rectangular coordinates on one component to rectangular coordinates on another.
(2) calculation method
Rectangle [] computeDifference (Rectangle R1 journal rectangle R2) Rectangle computeIntersection (int x, int y, int width, int height, Rectangle dest) Rectangle computeUnion (int x, int y, int width, int height, Rectangle dest) int computeStringWidth (FontMetrics fm, String str) boolean isRectangleContainingRectangle (Rectangle a, Rectangle b)
The above methods calculate the difference, intersection and union between two rectangles, determine whether one rectangle includes another rectangle, and calculate the pixel width of a string.
(3) Mouse button information
◆ boolean isLeftMouseButton (MouseEvent anEvent)
◆ boolean isMiddleMouseButton (MouseEvent anEvent)
◆ boolean isRightMouseButton (MouseEvent anEvent)
Determine which mouse button was pressed by a given mouse event.
(4) access control method
◆ Component findFocusOwner (Component c)
Gets the focus component of a given component.
◆ Component getLocalBounds (Component aComponent)
Gets the Bounds information for a given component.
◆ Component getRoot (Component c)
◆ JRootPane getRootPane (Component c)
Gets the root pane of a given component.
◆ Window windowForComponent (Component aComponent)
Returns the window Window of a component.
(5) component drawing
String layoutCompoundLabel (FontMetrics fm, String text, Icon icon
Int verticalAlignment, int horizontalAlignment, int verticalTextPosition
Int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR
Int textIconGap)
String layoutCompoundLabel (JComponent c, FontMetrics fm, String text, Icon icon
Int verticalAlignment, int horizontalAlignment, int verticalTextPosition
Int rizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR
Int textIconGap) void paintComponent
(Graphics g, Component c, Container p, int x, int y, int w, int h)
These two methods are used to rearrange the text and icons on swing buttons and labels.
◆ void paintComponent (Graphics g, Component c, Container p, int x, int y, int w, int h)
◆ void paintComponent (Graphics g, Component c, Container p, Rectangle r)
Draw a component on any graph.
The above is all the content of this article "what is the use of SwingUtilities in Swing?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.