简体   繁体   中英

Screen Arrangement Control in Java

I am planning to implement a screen arrangement view for a desktop Java application. By screen arrangement view, I mean a view that allows to arrange several rectangles around a central rectangle, so that no gaps are allowed, much like the screen arrangement interface in eg macOS or Windows works:

macOS上的屏幕排列UI

The user would be able to drag the rectangles (except the central one) around and place them somewhere adjacent to another rectangle (that is connected to another rectangle that is connected to another rectangle .... that is connected to the central rectangle). The rectangles would automatically move to a correct spot if dropped at an incorrect spot.

控件的样机示例

I have experience in Java (Android), but little knowledge of User Interface design on desktop Java. I am using Swing for all UI I have already in my application.

I have done some research but could not find any similar implementation or question on SO.

However, I do not want to reinvent the wheel, so before I start implementing from scratch, I have these questions:

  1. What search terms could I use for further research?
  2. Are there any built-in components I could use as a base?
  3. Is there maybe an open-source component I could use?
  4. Does anyone know an implementation of such a control in any language that I could use as a reference?
  5. How would you implement such a control?

Any help is highly appreciated!

1.What search terms could I use for further research?

One of the search term you can use is drag and drop (and that is what you plan to do).

2.Are there any built-in components I could use as a base?

Java has built in classes for drag and drop. Take a look here: Drag and Drop Turotial

3.Is there maybe an open-source component I could use?

I am sure there are quite a few if you try Googling it. But, personally I don't think you need an open source component to perform your required task. Java Swing already has pretty good classes available which is easy to use and more than enough to handle what you want.

5.How would you implement such a control?

Other than using the DnD from Java, a similar feature can be implemented using custom painting + various listeners such as Mouse motion listener. This way, you set what ever rules you want over the components that is being dragged / clicked / mouse-over. For example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM