Java – Custom swing components: questions about methods

I'm trying to build a new Java swing component. I realize that I may be able to find something that can meet my needs on the network, but this part is my practice to learn to achieve this goal

I want to build a swing component that represents the Gantt chart It's good (although it's not essential for people to be able to interact with it (for example, sliding tasks to adjust time)

It feels like the best way is to inherit JComponent and override paintcomponent () to "draw a picture" of what it should look like, rather than trying to stuff everything into a custom JTable

I've read several books on this topic and read a few examples (most notably things like jxgraph) – but I'm curious about something

>When do I have to switch to UI delegation, and when can I insist on fiddling with paintcomponent () to render what I want? > If I want other swing components as child elements of my component (for example, I want a text box on my Gantt chart)

>Can I stop using paintcomponent()? > Can I position them anywhere in the Gantt chart, or do I have to use the normal swing layout manager

Thank you in advance

-Master

Solution

I think I worked for java a few years ago The article written by. Net is still correct today Doing everything in a single class will make you faster at first, but very fast I strongly recommend separating the model (in the main class) from the view (UI delegate) This view is responsible for:

>Interact with users – mouse, keyboard, etc. > paint > create "worker" subcomponents as needed

In the medium and long term, this method is verified again and again in Flamingo component suite. You can use it as an additional reference point (in addition to the implementation of the core swing component)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>