Swing Utility: Swing Utilities

Source: Internet
Author: User

Swing offers a number of utilities that are used internally within swing components, and the Swingutilities class is one of them. It provides a number of methods involving computing, transformation, access control, layout, etc., which have been widely used in various swing components. Of course, we can also apply it to our own program.

Here's a look at one of these practical features.

(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 point coordinates on one component to a coordinate point on another component.

void Convertpointfromscreen (point P, Component c)

Converts a screen twilight coordinate point into a component's coordinate point.

void Convertpointtoscreen (point P, omponent c)

Converts a coordinate point on a component to a screen twilight coordinate.

Rectangle Convertrectangle (Component source, Rectangle Arectangle, Component destination)

Converts the rectangular coordinates on one component to the rectangular coordinates on another component.

(2) Calculation method

Rectangle[] Computedifference (Rectangle r1,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)

These methods compute the difference set, intersection, and set of two rectangles, and also determine whether a rectangle includes another rectangle and compute the pixel width of a string.

(3) mouse button information

Boolean Isleftmousebutton (MouseEvent anevent)

Boolean Ismiddlemousebutton (MouseEvent anevent)

Boolean Isrightmousebutton (MouseEvent anevent)

Determines which mouse button is pressed with the given mouse event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.