The "proper" way to do it is probably to subclass JTable and override the method that implements the UI for the table header.

I don't see anything at all improper about taking the JTableHeader and making use of it for specialized purposes. JTable goes to the trouble of giving us a getTableHeader method, and we have all the listeners we need to draw extra widgets around the JTableHeader that move as the columns move. The whole system seems designed to make this sort of thing possible.

On the other hand, subclassing is dangerous and error prone. I don't claim to have any special knowledge about what is proper, but using subclassing is asking for trouble.


@CoilFyzx wrote

So what would be the best practice for me to get this done please?

  • @JamesCherrill argeed +1, (excluding subclassing)

  • never to subclass JComponents, majority of JComponents has own Model implemented in APIs

  • never to subclass JTable, JTable is simple, very simple JComponents, subclass XxxTableModel instead

  • never to subclass JComponents View, why complicating the simple things by subclassing, this idea is very fragille, breakable for all of compound JComponents,

  • most of newbee can lost in methods betweens View_To_Model and Model_To_View, use DefaultWhateverModel instead of AbstractWhateverModel

  • subclass container nested JComponents, there to override getMin/Max/PreferredSize()

  • create an local variables for all JComponents that will be reusable in Apps life_cycle, then this variable cant required getter/setter (or another ZOO), only simple constructor for whole/current JVM

@CoilFyzx wrote

My main objective: Is to create a table that accepts user data into a table. The tables design(which is what I'm trying to accomplish now), is to create a structured view of the information(which really is the purpose of every table).

So the user will add data to the section labelled subject letters.

As it relates to functionality, that will be simple to implement. All I wish for is the visual design. I don't know how to make that any more clear(I sya this because I keep being asked for the objective or my goal; which is exactly to create what I designed in the image).

  • simple lesson (by default I don't waste with my time about used LayoutManager for posts to forums, have to use SpringLayout, resp, GBC for input data)

Edited by mKorbel


I think I was too casual in the language of my post. I should have said something more like "subclass or replace the component in JTable that is responsible for painting the headers"
... but then I came to Java from SmallTalk, and am a big fan of appropriate subclassing. (Not everybody agrees, but this isn't the place to debate it.)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.