Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems with design patterns in the Swing framework?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What are the problems with the design patterns in the Swing framework? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Swing control is a lightweight GUI control developed for AWT control, which adopts the Composite design pattern. However, because there is no clear boundary between Component and Container, almost every individual component of Swing is a container and can add other containers or components. The following editor will explain what will happen to the design patterns in the Swing framework.

What are the problems with design patterns in Swing framework

1. It is very inconsistent with people's intuition: if too many panels are added to the various components on the GUI of Swing, the level of each component will be very deep, it is very troublesome to deal with problems such as focus management, and the transformation of coordinates is also very complicated. Because there are too many parent-child relationships, you only look at GUI without looking at the code, so it is difficult to distinguish the parent-child relationship of components intuitively.

two。 Trouble in use: because the Swing component itself cannot tell whether it is a component or a container, many container methods, such as setEnabled, have no effect. You need to write code to traverse all sub-components and call the same methods for all sub-components. Similar methods that set transparency also have this problem. If you set a container transparent, you also need to set the transparency properties of all sub-components, and many methods of components and containers are not well defined. This is not a problem for people who understand the structure of Swing, but it is very confusing for those who are familiar with other GUI libraries, because the method calls on many containers have no effect.

What are the problems with design patterns in Swing framework

3. Layout difficulties: programmers using Swing development interfaces will find that even though Swing provides so many layout managers, it is very difficult for you to make professional interfaces through these layout managers, because the layout manager relies heavily on the various states of the parent container and child components, although the latest version of Swing provides a method similar to component and container spacing, it has not been adopted by most layout managers In fact, it is not that the layout manager is not strong enough. In fact, many professional interfaces need to be well defined at the component level, such as getPreferredSize,getMinimumSize,getMaximumSize methods. These methods are so uncertain that layout managers cannot rely too much on these methods. In addition, many Swing components are drawn according to the size of the container, which also creates a lot of uncertainty. Many people like to use NullLayout, which may be the reason. Customers need a stable and predictable interface. If you use a layout manager, you will find that the interface is displayed differently in different systems.

Compared with many GUI class libraries, you will find that their definitions are more stringent, such as the JavaMELCDUI class library, where components and containers are strictly separated, the addition of components is strictly restricted, the layout is also very strictly defined, and there is no layout manager, support such as scroll bars are hidden at the bottom, which really reduces the burden on GUI developers.

In general, the Composite design pattern should be used with caution, and if it must be used, the boundaries between components (Component) and containers (Container) must be well defined, otherwise many functions will fall into meaningless parent-son traversal routines, increasing complexity without bringing many benefits.

This is the answer to the question about what will happen to the design pattern in the Swing framework. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report