JTable column headings - how to change after instantiation

Is there a way to change the column headings on a JTable AFTER is has already been instantiated? I reviewed the JTable, TableModel and TableColumn API's in detail. The only method I found related to this is the 'getColumnName' in TableModel. But there is no associated 'setColumnName'.

Hi!
You can use the method setHeaderValue(Object) of TableColumn. I wrote a small example:
import javax.swing.*;
import javax.swing.table.*;
public class TableExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        Object[][] data = {
            { "a1", "a2", "a3" },
            { "b1", "b2", "b3" },
            { "c1", "c2", "c3" },
        Object[] headers = {
            "1", "2", "3"
        JTable table = new JTable(data, headers);
        frame.getContentPane().add(new JScrollPane(table));
        frame.pack();
        frame.setVisible(true);
        //  Change header for first column
        TableColumnModel columnModel = table.getColumnModel();
        TableColumn col0 = columnModel.getColumn(0);
        col0.setHeaderValue("New header value");
}Søren

Similar Messages

  • How do I restore column headings in Response table after accidently deleting them? Undo doesn't work.

    How do I restore column headings in Response table after accidently deleting them? Undo doesn't work (only seems to go back one level). I also have so many headings I won't be able to type them in manually!

    With the help of information from user, ptressel, in [https://support.mozilla.org/en-US/questions/1032154#answer-673322 a post here about the existence of sessionstore.js when version 33 was released], I was able to easily recover my tabs and tab groups as follows:
    # close Firefox and, perhaps, allow a few seconds (30s?) for any final closing of files;
    # check to see if you have a sessionstore.js file in your profile folder, named like the one I documented in my original post above;
    # if it is not timestamped prior to the discovery of your problem, open the sessionstore-backups folder;
    # check if the recovery.js file is suitably timestamped and, if not, the recovery.bak.
    # At this point, you are likely to find that none of them are prior to your problem occuring. If so, open your backups of this folder and go through steps 2-4 to find a file prior to your problem occuring.
    # When you find a file, copy it to the root of your current profile folder and name it, "sessionstore.js"
    # Open Firefox. Mine opened up as desired.
    This is a Windows solution. Sorry I can't comment on other platforms, but I'd bet that as this is just a file copy and renaming, it is likely the same.
    For Windows users, you may find you need to sign out and login as an administrator in order to access the backups. You need not logoff your standard account, but do have Firefox closed as described above.
    Hope that helps.

  • Changing default JTable column headings

    Hi,
    I've created a simple JTable using the following constructor:
    JTable table = new JTable ( numRows, numCols);
    and I would now like to change the default column headings ("A", "B", "C" etc) to something else. I'm trying to use the following method
    setColumnIdentifiers
    but how do I access the DefaultTableModel associated with table so that I can call this method?
    Is there another way of changing the headings of my simple table?
    Thanks a lot,
    Leori.

    myTable.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Foo");

  • Row and column headings-how to print without them

    Currently Epson C64 and appleworks 6.2
    How can I print the spreadsheet without the row and column headings as there doesnt seem to be a place to choose whether to how or not
    Thanks for replies
    Whilst writing, too many instances of the coloured wheel rotating, nothoing showing on screen, suddenly whole sentences appear. Very irritating, so how can I stop this ?

    I'm glad the AppleWorks info was helpful.
    About the colored wheel issue: does this happen in all applications in which you are typing? Are you doing other things in that app at the same time. For instance, if Safari is one of the problematic apps, are you also downloading at the same time? I have seen this issue a few times - very rarely - and have found that a restart usually gets things back to normal. I'm not sure if this will be a helpful workaround for you, but it has had some success.

  • JTable Column Headings

    While adding a Jtable without a scrollpane, the column headings are not displayed, why?

    Why does JTable doesn't automatically display the table header?Because its actually two components. One is the JTable and one is the JTableHeader.
    If you add the JTable to a scroll pane (the most common situation), there is code in the JTable class that checks if the table is being added to a scroll pane. The scroll pane has a well know layout so the header can be added safely to the column header of the scroll pane.
    However if you add the table to a panel you don't know what layout manager is being used is so you don't know where to add the header so it is left up to the programmer to customize the layout appropriately.

  • JTable Column Headings not displaying

    Hi
    I have recently made a Jtable a node of a Jtree.
    My table shows (semi-correctly) and is editable.
    I can't seem to see the headings of each column. and the left hand border line of the table is missing.
    Anyone know why this is?? I presume that I cant resize my columns due to the fact I cant see the headings.
    Thanks
    mike

    If you don't want to put the table in a scrollpane you can put it on a JPanel too...but use the BorderLayout and add the table to the center and the tableheader to the North portion.

  • List web part column alignment: how to change?

    I have a wide list web part but all the three columns are aligned to left. So there is a huge white area on the right. Was it like this also in 2010? Can I change it so that the columns would be spread also to right?

    Try these steps:
    Open the page containing the list web part in Edit mode
    Open the web part's settings panel
    Set the web part's width as desired

  • How to change the particular column background  color in jTable?

    I am woking with a project, in which I am using a jTable. Then
    How to change the particular column background color in jTable?

    Use a custom Renderer. This is the JTable tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • How to Change the Visible names in JDBC IView ?

    While Creating a JDBC View, in one of the steps we select the column names from a schema which we want to view in a IView.While doing so in the next step there is a text field called <b>visible names</b> which is editable to change the column names.How to change the Column aliases or visibles names as is it not getting saved when we move onto the next screen ?.How to Configure the Visible Column names while configuring a JDBC IView ?.
    Can anybody please help me !.

    Hi Abhilash
    If I'm not wrong I saw something about this here (SDN), in a technical article about how to create a JDBC iView . I tried to get the link to the article but it seems there's a problem with the site, sorry...
    By the way, I had the same problem, and according to the   article this was not possible in the version EP6 SP2 but there was a plan to implement this in newer versions. I tried also to use a SQL command with the column names I wish to display but it didn't work either.
    Try to find this article in the EP Technical Article to confirm this info, ok ?
    Rgds,
    Fernando

  • How to change JTable column header text

    How do you set the text in the JTable column headers? I know you can create a JTable specifying the text in an array:
    <li>JTable(Object[][] rowData, Object[] columnNames)
    But if you create the JTable specifying a TableModel,
    <li>JTable(TableModel dm)
    the header text defaults to "A", "B", "C", etc. I cannot figure out how to access the text in the header names so it can be changed to something useful. I know how to get the JTableHeader for the table, but it does not seem to have methods for actually setting header values.

    I'm sure that model allows you to specify header values so you don't have to do so manually. I would be very surprised if it didn't override the default getColumnName() method to provide a reasonable names.She wasn't writing the class, but [url http://forums.oracle.com/forums/thread.jspa?messageID=9200751#9200751]outlining a design for me to implement. And, based on a previous comment I had made, I think she assumed I wanted the new design to look as much like the old as possible. There were no headers in the original design, which wasn't even a table.
    Anyway, this works:
        final static String statisticsColumnNames[] = {
         "Type", "Count",
         "Red QE", "Green QE", "Blue QE", "Average QE",
         "Distance"
         qErrors = new QEBeanTableModel();
         JTable errorTable = new JTable(qErrors);
         TableColumnModel tcm = errorTable.getColumnModel();
         for (int col = 0; col < statisticsColumnNames.length; col++)
             tcm.getColumn(col).setHeaderValue(statisticsColumnNames[col]);
    It looks like setHeaderValue() on the TableColumn is what I was looking for.Again, only used if you are dynamically changing the values at run time or you don't like the defaults provided by the Bean-aware model.I coded the above before I read your last post. The QEBeanTableModel is extremely specific to my program. I.e. I cannot imagine it being used anywhere else. Would it still be better to implement a getColumnName() within the table model? Looking at your [url http://www.camick.com/java/source/RowTableModel.java]RowTableModel.java source, I can see that it would not be difficult to do so.
    Just decided to add the getColumnName() method. This whole sub-project is based on implementing a clean modern design (and learning about Java Beans). You've clearly stated twice that the method I have implemented is for dynamic header values only, which has already answered what I asked last paragraph.

  • (simple q) how do I change the font in a JTable column header?  thanks

    how do I change the font in a JTable column header?
    thanks

    JTableHeader header = yourTable.getTableHeader();
    // Set to serif, bold, size 12...
    header.setFont( new java.awt.Font( "serif", 1, 12 ) );
    // you can set others like color and border, too.
    header.setBackground(Color.white);
    header.setBorder( new EmptyBorder(15,2,15,2) );

  • How to change font in just one column of JTable

    I have a table with 4 column.
    I want to have Courier font in column number 2, and Arial in columns number 1, 3 and 4.
    With:
    table.setFont(new Font("Courier New", Font.PLAIN, 12));
    I can set fonts in all columns but how to set font in just one column.
    Thanks
    Srdan

    Hi,
    there are 2 methods of JTable where every rendering resp. editing component "comes" through - prepareRenderer(...) and prepareEditor(....) - by overwriting this methods and calling its super method first you get the component and can manipulate it before you return it. This component is exactly that, what is used for rendering resp. editing afterwards.
    greetings Marsian

  • How to change background color to JCheckBox in a JTable?

    Dear Friends,
    I have an JTable in my application. It has four columns. First, third and fourth column contains JCheckBox (JCheckBox is created using Boolean.class), secod column contains values.
    I have to change some of the cell color where JCheckBox is present.
    Could anyone please tell me how to change the color of the cell in the JTable?
    Thanks in advance,
    Sathish kumar D

    You would use a custom renderer.
    To get better help sooner, post a SSCCE that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db
    Alternative link: SSCCE
    Edited by: Darryl.Burke

  • How to change sorting in column view in Maverick

    I understand how to change the view and then "arrange by".  In my columns, they list from oldest to newest.  I don't see how to reverse that.  I want newest on top.  Also, how do I set the column width to what I want and save for all?  I can adjust the column width, but it defautlts back to the narrow setting shortly after.

    Excuse me my English. It is not my problem.
    I need to ensure this thing:
    When user click on any head of column in output table (table view) it must not call any event. All data must stay on same rows.
    Example. A have table:
    Col1        Col2
    B           20
    A           30
    T           10
    D           60
    If I click on first head of column data will be sorted:
    Col1        Col2
    A           30
    B           20
    D           60
    T           10
    But if hierachy or structure are in first column rows cannot be changed.

  • How to change column heading in line item report

    Hello Experts,
    How to change the column heading in the line item report CJI4 or CJI3  ?
    for eg: The field WBS will show as Object in the heading. Here  I would like to change to WBS.
    Is there a way to do this without changing ABAP code
    FATMAN

    Not possible through standard I guess.
    Enhancement you should be looking is COOMEP01 which includes the component EXIT_SAPLKAEP_009
    i.e., Line Item Reports: Customer-specific Formatting of the Lists.You use this enhancement to modify column headings.
    Regards
    Sreenivas

Maybe you are looking for

  • Integration of BI Publisher with presentation services

    Hello, I have installed and configured OBI Answers and Publisher in a Linux infrastructure and configured thro' Websphere/IHS. Answers/Dashboards is working fine. I am trying to integrate BI publisher with OBI answers/dashboards. This is working fine

  • Drop shadow on img missing

    Hi! I want a drop shadow on my images. I have created this div to do that: .shadow{ box-shadow: 5px 5px 3px rgba(65, 65, 65, 0.5); Then I added the div class to my images. But it doesn't work on the images already inside a div tag. E.g. my two pictur

  • Adobe Reader 7.0 uninstall problem

    Web site provided by Claudio Gonzales didn't work.  Any other suggestions?

  • Unknown blank screen.

    Excuse me, i have weird blank screen problem. After I'm closing the screen, Im going to open it again to make sure my Laptop is ok but what i got is blank screen but the Laptop still working. Even the finger swipe device still on, telling me to swipe

  • HT1349 how can i find my iphone 4?

    I lost last november 13 2011,my wife recieved a txt it was from my cell it look like green txt.and after that time my wife called in my cell then the guy answeered .