Custom Swing component: questions on approach

Posted by phatmanace on Stack Overflow See other posts from Stack Overflow or by phatmanace
Published on 2010-06-08T22:25:21Z Indexed on 2010/06/08 23:32 UTC
Read the original article Hit count: 264

Filed under:
|
|
|

Hi Folks,

I'm trying to build a new java swing component, I realise that I might be able to find one that does what I need on the web, but this is partly an exercise for me to learn ow to do this.

I want to build a swing component that represents a Gantt chart. it would be good (though not essential for people to be able to interact with it (e.g slide the the tasks around to adjust timings)

it feels like the best approach for this is to subclass JComponent, and override PaintComponent() to 'draw a picture' of what the chart should look like, as opposed to doing something like trying to jam everything into a custom JTable.

I've read a couple of books on the subject, and also looked at a few examples (most notably things like JXGraph) - but I'm curious about a few things

  • When do I have to switch to using UI delegates, and when can I stick to just fiddling around in paintcomponent() to render what I want?

  • if I want other swing components as sub-elements of my component (e.g I wanted a text box on my gantt chart)

    • can I no longer use paintComponent()?
    • can I arbitrarily position them within my Gantt chart, or do I have to use a normal swing layout manager

many thanks in advance.

-Ace

© Stack Overflow or respective owner

Related posts about java

Related posts about swing