Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What might control whether a JTable header appears with default application LAF or not?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Location
    Ottawa
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What might control whether a JTable header appears with default application LAF or not?

    I'm in the process of adding a new tab to a tabbed pane in a 12 year old GUI. This tab will, like several other tabs in the tabbed pane, include as one of its components a JPanel containing a JTable mounted in a JScrollPane. Standard stuff, and when I put it together, it all works fine.

    What's driving me crazy, is that when I look around the GUI, most of the JTables present have table headers which show up with what I can only assume is the default environment LAF (haven't been able to find any interactions with the UIManager, setting it, anywhere). As below, quite nice:

    AltimeterTableHeader.png

    When I load my JTable subclass in the JScrollPane, then load that into the JPanel subclass that displays it, everything works fine...but there doesn't appear to be any way in creation that I can get a header that looks like anything other than the Java Tutorials' plainest. As below, functional but drab:

    MyTableHeader.jpg

    I've spent the past couple of days analyzing code--some parts written in Java 1.2, most in Java 1.4, and now I'm looking to add my material in Java 6--trying to find any consistent similarity or difference between cases presenting metal-LAF vs flat headers, and drawing a complete blank. Sometimes the tables with metal-LAF headers are JTable subclasses (no subclass code relates to headers or rendering, that I can see) and sometimes vanilla JTables. Sometimes (the older instances) have been set up with custom TableSorter code, and most times not--again, none of it seems to affect header rendering. Sometimes custom cell renderers have been applied--the most common setting up alternating grey and white row colours--and sometimes not. And all of these tables seem to have been loaded to standard JScrollPanes. There's some variation in the calls around them, to set viewports, fill viewport heights, and so on, but again, nothing that seems to touch header rendering.

    And of course there isn't a tutorial in sight anywhere, that offers any clues as to how the default-LAF headers might be showing up.

    Can anyone point me in the direction of what, between one case of table-in-scrollpane-in-panel, and the next, might play a part in determining JTableHeader LAF?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: What might control whether a JTable header appears with default application LAF or not?

    It looks to me like one of your tables has a custom renderer on it? In fact, that header looks like JButtons instead of a standard header.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Location
    Ottawa
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What might control whether a JTable header appears with default application LAF or not?

    Quote Originally Posted by KevinWorkman View Post
    It looks to me like one of your tables has a custom renderer on it? In fact, that header looks like JButtons instead of a standard header.
    It does, in fact, look like all the enabled JButtons around. Which is a useful thought, and possible lead...and hot damn, there it is.

    It turns out that back when most of the tables displaying default-LAF were coded (Java 1.2) somebody implemented a SortButtonRenderer extending JButton and implementing TableCellRenderer, and this was in fact applied to all of the tables showing default-LAF, and none of the ones that weren't. The reason I failed to pick up on this in two days worth of searching, was because the app is also set up to support GUI language switching on the fly, and every time we switch languages, when the tables' TableColumnModels change, the header renderer has to be re-set on each column. This is handled as part of the language-switching code, well away from the main path of GUI construction where all other renderers are set.

Similar Threads

  1. Adding column to JTable with JSlider determined header
    By oli_t in forum AWT / Java Swing
    Replies: 3
    Last Post: March 6th, 2013, 02:13 PM
  2. How to select default value of jRadioButton inside jTable
    By tomrey in forum AWT / Java Swing
    Replies: 1
    Last Post: February 27th, 2013, 05:12 PM
  3. Customize Jtable header
    By md_suzon in forum AWT / Java Swing
    Replies: 1
    Last Post: October 11th, 2011, 04:16 PM
  4. Metal LAF JScrollPane rendering bug?
    By tpsuk in forum AWT / Java Swing
    Replies: 3
    Last Post: February 8th, 2011, 11:22 AM

Tags for this Thread