- Everything appears on screen is basically a component. JComponent is the Swing superclass of all things that draw on screen. For example, JLabel is a built-in JComponent that displays little text string. What you usually do is to create components objects and install it onto screen or their container.
- Frames (JFrame) are the outermost components. A JFrame represents a single window. Each JFrame component has a "content pane" JComponent that contains all components in the frame. You can use
frame.getContentPane()to get the content pane. Content pane uses a Layout Manager to size and position its components. Frame has a convenience
setLayout()that go to its content pane.
- Components are placed inside other components which form a nesting hierarchy from outer to inner components. And each container is behind the components it contains. Layout Manager sizes and places those components according to some 'policies' or 'intents' of the layout. Don't call
setSize()yourself, the layout manager controls that! Instead, do call
setPreferredSize(), to register a preference before the layout manager lays everything out (before calling
- Three basic layout manager:
FlowLayout, BoxLayout, BorderLayout. Flow layout arranges components left-right, top-down like text. Box layout aligns components in a line, either vertically or horizontally. Border layout puts main content in the center and decorate with 4 things around the outsize -- north, south, east, west.
- Swing thread, or Event-dispatch thread, Composite pattern and Observer/Observable patterns basically form the underlying architecture of Swing GUI system.
- A common technique in Java GUI code is to use an anonymous inner class to create a 'listener' class object and register it using
addXXXListener()method to a Observable, e.g a button, on the fly.
OuterClass.InnerClass innerObject = outerObject.new InnerClass();
android.view.View) is an important interface for rendering UI objects. Inside it, a method called
invalidate()plays a key role.
invalidateis simple, it marks a region on the view to be 'dirty', which tells the android system that region must be redrawn soon in the near future. The region can be the whole
Viewor just a designated region passed to
invalidate. And obviously, invalidating only a small portion of the view can have some performance advantages for the UI system. Therefore, make sure you use
onDraw( )method (a method of class
View). Instead, you use the
invalidate( )method to mark rectangles as dirty. The window manager will combine all the dirty rectangles at some point in the future and call
onDraw( )again for you. The dirty rectangles become the clip region, so screen updates are optimized to only those areas that change.
Click to focus
Focus follows pointer
- Page 1 of 1 ( 7 posts )