Remove Column Headers from a JTable in a JScrollPane

Hi,
I'm just wondering how to remove the column headers from a JTable in a JScrollPane.

Here are two ways to do it, with different visual outcomes...
import javax.swing.*;
public class Test {
    public static void main(String[] args) {
        Object[][] rowData = {{"A", "B"}, {"C", "D"}};
        Object[] columnNames = {"col 1", "col 2"};
        JTable table1 = new JTable(rowData, columnNames);
        table1.getTableHeader().setVisible(false);
        JScrollPane sp1 = new JScrollPane(table1);
        JTable table2 = new JTable(rowData, columnNames);
        final JScrollPane sp2 = new JScrollPane(table2);
        JPanel contentPane = new JPanel();
        contentPane.add(sp1);
        contentPane.add(sp2);
        final JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(contentPane);
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                sp2.setColumnHeader(null);
                f.setLocationRelativeTo(null);
                f.setVisible(true);
}

Similar Messages

  • Can you remove column headers from report downloads?

    I'd like to remove the column header from the report downloads. For example, the report download file currently looks like:
    EMPNO,ENAME
    7839, KING
    7698, BLAKE
    Where as I'd like it to just be:
    7839, KING
    7698, BLAKE
    Does anyone know if this is possible?
    Thank you,
    Martin
    http://www.talkapex.com

    There is a work around that I used before:
    - Create a new page.
    - create a report region and copy your origional report query in it
    - in report attributes >> choose no header
    - in report attributes >> choose "CVS report" as your new report tempate.
    - go back to your origional report, create a button in that page ( call it EXPORT ) that submits as EXPORT
    - create a conditional branch that goes to your new report page , make it conditional ( when EXPORT button is clicked)
    This way, you will have a new EXPORT button on top ( or whereever you want ) of you report, when you click on it , it shows a download prompt for your export , the export won't have headers..
    Sam

  • How to remove a row from a jtable with DefaultTableModel

    Hi to all,]
    I want to remove a row from jtable. I am using DefaultTableModel.
    I have got some example but every example is given with AbstractTableModel
    Please help me...
    Thanks and Regards

    I want to remove a row from jtable. I am using DefaultTableModel.How do you program without reading the API.
    The name of the method you use is "removeRow". How hard is that to find by reading the API?
    Not only do you not bother to read the API, you don't even bother to read and respond to your old postings when you get help:
    http://forum.java.sun.com/thread.jspa?threadID=5137773
    http://forum.java.sun.com/thread.jspa?threadID=5134667
    http://forum.java.sun.com/thread.jspa?threadID=5131162
    Your on your own in the future.

  • Remove Column Headers in FlexUi Layout

    HI,
    I am displaying a Km folder using flexui layout....I am using the following components,
    Layout Controller:GridListLayoutController
    and the modifed versions of ConsumerFileListRenderer and ConsumerResourceRenderer.
    The resources are getting displayed as list items, but I want to remove the column headers.
    Please help me!
    Regards,
    Sandip

    Hi Sandip,
    You should try to use 'noTitle' modifier for displayed properties of your resources on the list. Column header will be not shown for properties with this modifier. Here is na example:
    description(noTitle),
    Column with description property will be shown without header.
    Regards,
    Michal

  • SQL Developer: How do I copy data with Column Headers from the output grid?

    Hello,
    I am using Version 2.1.1.64.
    I run a SQL query, I get the results grid in the "Query Result" window down below. Say I get 10 rows returned, with 5 columns.
    I want to Copy this entire grid, plus the column headers/names, to the clipboard. So I can paste it under the original query to document the results of that query.
    I can't find any way to do this. I can copy/paste the results grid, but it doesn't copy the headers.
    The only way I see to do it is to go through numerous steps to Export to a TXT file, then paste that. Unfortunately, that is a lot of wasted steps if I need to do this over and over, plus, the output gets pasted in an ugly format with double quotes, etc.
    It seems like the simplest functionality is to copy/paste the entire results grid, and of course you might the headers. Why is this so complicated/impossible to do?
    (I believe Toad has the same problem. DBArtisan allows you to copy/paste the entire results, plus headers, though.)
    Any assistance would be appreciated!
    Thanks,
    John

    Ah, ok...
    I had tried that before, and it didn't work, it seemed to copy the path of filename I was using. But I think that was because I had clicked on a Column Header first, and it had asked me if I wanted to filter. I think then it lost track that it was in the grid. It's a little flukey.
    What I did now was to click on an individual cell in the output, then hit CTRL-A to select all, then hit SHIFT-CTRL-C. That gives me exactly what I want.
    Thanks very much for your quick solution, I appreciate it!
    John

  • Remove all rows from a JTable.

    I carnt seem to work out how to do it, surely there is a way.
    Thank you

    for those people who search for a thread like this and find it i solved it by doing this.
    DefaultTableModel d =(DefaultTableModel)<Your Table Name>.getModel();
    int rowCount = d.getRowCount();
    for(int i=0; i < rowCount; i++){
    d.removeRow(0);
    The reason for the "0" in remove row is because it will automatically resize the rows down one and effectively you want to remove all the rows until there isnt any in the last row. :)

  • Export JTable Column headers to Excel document

    Hello all!!! I am having a small problem while trying to export some data from a jTable to an excel document.
    I have a jTable and I use a custom TableModel with this:
    private String[] columnNames = {"First", "Second", "Third", "Forth"};as names for each column of the table.
    The thing I am trying to do is to export exactly the same "headers" from the columns of the jTable to the excel spreadsheet using Jakarta POI. Unfortunately I don't know how to do it and I haven't found anything yet on this forum. Can anyone help me with this?
    In simple words I want to know how I can have the same headers from my jTable columns, with the headers from the excel doument I will create.
    Many thanks in advanve!!!
    Kostas

    Thank you for your reply first of all. The problem is how to get the heading text and how to put it to the excel's first row OR to excels "headings" (if it is possible...). [in other words replace A,B,C,D from the excel document with the headers I get from the jTable...] .
    I hope now you can see what I am looking for... If there is no solution to this please tell me what are the alternatives. (B) could be a good example.
    Thanks you very much!!
    Kostas

  • How do i completely remove headers from email messages

    Hi everyone. Can someone tell me how to completely remove the headers from showing up in messages i send, forward or receive? I know how to make the headers shorter, but that's not what i want to do. I want to completely remove them from all outgoing and incoming messages. Thanks!

    Hi lpagillo.
    Not sure what you mean. You cannot remove the headers from the messages themselves. If what you want is them to not show up so that they don’t take up space on the screen, choose None in Preferences > Viewing > Show header detail.

  • Cant see jtable column headers

    I have my jtable in a container and i am displaying that container in a jframe. I cant see the table column headers. I cant use a jscrollpane and need to make the table headers visible. I can see the table fine with all its information in it. When I do a System.out.println(TableModel.getColumnName(int)); i get the correct column header name so I know that the column headers are existing. I would appreciate any help that you can give

    the last answer did not help me out. I reposted this with more information, such as i am placing my table in a container and not in a scrollpane. I added the code below and it still did not work
    content.add(jt.getTableHeader(), BorderLayout.NORTH);
    content.add(jt, BorderLayout.CENTER);
    I can still only see the table. I pasted code below where I create my table and repaint it. I have it set up where my table is in a JPanel. I have is set up so that I can move it around and resize it with the mouse. This all works and I can see the table but there are no headers.
    public FigTable(DefaultTableModel inTableModel, LEditor inLEditor)
              super(50, 50, 350, 200);
              setLineColor(Color.blue);
              setFillColor(ColorMenu.kColorOfNoFill);
              fEditor = inLEditor;
              content = fEditor.getGEFPanel().getDrawingPanel();
              importTable(inTableModel);
              fEditor.init();
              fEditor.inval();
    public void importTable(DefaultTableModel inTableModel)
              jt = new JTable(inTableModel);
              tRows = jt.getRowCount();
              tColumns = jt.getColumnCount();
              content.add(jt, BorderLayout.CENTER);
              content.add(jt.getTableHeader(), BorderLayout.NORTH);
    public void paint(Graphics g)
              jt.setBounds(_x, y, w, _h);
              if (_h >= tRows && tRows != 0)
              jt.setRowHeight(_h / tRows);
              if (isSelected())
                   drawHandles(g);
              if (_filled && (getFillColor() != null))
                   jt.setBackground(getFillColor());
              if (getLineColor() != null)
                   jt.setGridColor(getLineColor());
                   jt.setBorder(BorderFactory.createLineBorder(getLineColor()));
         }

  • Fixed jtable column headers

    Does anyone have an example of fixing column headers for a JTable. Basically I want the column headers to be displayed when scrolling down the table.

    check the examples provided in "How to use table" -
    "http://java.sun.com/docs/books/tutorial/uiswing/components/table.html"
    The tables have fixed column header when u scroll down..

  • Removing rows from a JTable

    How can i remove a row from a JTable??

    You need to extends AbstractTableModel rather than use DefaultTableModel as I think from memory this just uses an array to store data.
    If you use a vector in your subclass to store your rows, then you can do something like this:
        public boolean delete(int rowIndex)
            if (rowIndex < 0 || rowIndex >= rowVector.size())
                return false;
            else
                int day = 0;
                MyRowClass row = rowVector.get(rowIndex);
                rowVector.remove(rowIndex);
                rowCount--;
                fireTableRowsDeleted(rowIndex, rowIndex);
                return true;
        }HTH
    Paul C.

  • Hiding the column headers in boxed view

    I've created a custom list that I'm displaying in boxed view.  Here's a sample of the columns:
    Business Systems Manager
    Project lead
    Project number
    SFA?
    Etc...
    In boxed view, it displays like I have it here - vertical.  The names of the people and info display next to each item. 
    However, the web part is still displaying the column headings across the page like in this example:
    Business Systems Manager - Project Lead - Project Number - SFA? - etc...
    Some of my custom lists carry on for 12 or 13 columns and the main page view has about 6 or 7 of them so needless to say, the extra real estate the column headers (which are completely redundant because the column heading info is IN the boxed view!!!) are taking up is killing the layout of the page.
    Is there anyway to remove the column headers from the boxed view with out of the box Sharepoint?   Or is Designer required?
    Thanks!
    Lorraine

    This worked well for me:
    1) Add a Content Editor Web Part
    2) Click Source Editor
    3) Enter the following code:
    [css] <style> .ms-viewheadertr { display: none;} </style> [/css]
    4) Select Save
    5) Go to Layout and Select 'Hidden' 

  • String JMS Headers from TextMessage inside Message Driven Bean

    You get TextMessage inside onMessage(..) method of Message Driven Bean.
    When you do toString() on the textMessage instance, at first, you get JMS headers. After that only, you get your actula message that you put in the queue.
    I can always strip out the headers by String parsing. However, is there an elegant way (WebSphere Server Configuration, or MQ configuration, or JMS API) to remove JMS headers from the message so that I only get the actual message and no header?
    Hearder is like:
    JMS Message class: jms_text
    JMSType: null
    JMSDeliveryMode: 1
    JMSExpiration: 0
    JMSPriority: 0
    JMSMessageID: ID:414d5120514d444f43444141202020204377126c20001a01
    JMSTimestamp: 1132259105100
    JMSCorrelationID:null
    JMSDestination: null
    JMSReplyTo: null
    JMSRedelivered: false
    JMS_IBM_PutDate:20051117
    JMSXAppID:
    JMS_IBM_Format:MQSTR
    JMS_IBM_PutApplType:6
    JMS_IBM_MsgType:8
    JMSXUserID:clarkc
    JMS_IBM_PutTime:20250510
    JMSXDeliveryCount:1
    My actual message starts here after all the above headers ........

    You can get the message directly with getText() method. Following is the snippet of code.
    if (aMsg instanceof TextMessage) {
    TextMessage msg = (TextMessage) aMsg;
    String testMessage = msg.getText());
    Kishore.

  • Add and remove columns from JTable

    Help me please!
    A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
    I completely confused with it.....
    Here is my code for remove column:
    class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
                   else
                          JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         }

    It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
    My brain is boiled, I've try a lot of variants of code, but did't get right result :((
    It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
    I understand, that my code just hide columns, not delete from table model....
    But now I have not any decision of my problem...
    Thanks a lot for any help. :)
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.table.DefaultTableModel;
    class JTableF extends JFrame
         Object [] [] data = new Object [0] [2];
         JTable table;
         DefaultTableModel model;
         String [] columnNames = {"1", "2"};
         TableColumnModel cm;
         JTableF()
              super("Table features");
              setDefaultLookAndFeelDecorated( true );
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar MBar = new JMenuBar();
              JMenu [] menus =  {new JMenu("A"), new JMenu("B")};
              JMenuItem [] menu1 =  {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'),  new JMenuItem("Add column"), new JMenuItem("Delete column")};
              menu1 [ 0 ].addActionListener(new AddL());
              menu1 [ 1 ].addActionListener(new DelL());
              menu1 [ 2 ].addActionListener(new AddC());
              menu1 [ 3 ].addActionListener(new DelC());
              for (int i=0; i<menu1.length; i++)
                   menus [ 0 ].add( menu1 [ i ]);
              for (int i=0; i<menus.length; i++)
                   MBar.add(menus );
              JPanel panel = new JPanel ();
              model = new DefaultTableModel( data, columnNames );
              table = new JTable (model);
              cm = table.getColumnModel();
              panel.add (new JScrollPane(table));
              JButton b = new JButton ("Add row button");
              b.addActionListener(new AddL());
              panel.add (b);
              setJMenuBar (MBar);
              getContentPane().add(panel);
              pack();
              setLocationRelativeTo (null);
              setVisible (true);
         class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
                             tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
                        //cm = tableCModel;
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         class AddC implements ActionListener
              public void actionPerformed (ActionEvent e)
                   //table.setColumnModel(cm);
                   Object NewColumnName = new String();
                   NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
                   int i = model.getRowCount();
                   int j = model.getColumnCount();
                   Object [] newData = new Object [ i ];
                   model.addColumn ( NewColumnName, newData);
         class AddL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int i = model.getColumnCount();
                   Object [] Row = new Object [ i ];
                   model.addRow ( Row );
         class DelL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int [] HowManyRowsDelete = table.getSelectedRows();
                   if (HowManyRowsDelete.length !=0)
                        for (int k = HowManyRowsDelete.length-1; k>-1; k--)
                             model.removeRow (HowManyRowsDelete[k]);
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
         public static void main (String [] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        JTableF inst = new JTableF();

  • Adding/removing columns in jtable

    Hello everyone,
    i was looking for a way to add/remove columns from a jtable. The way i envision it working is... Initially have a predefined number of columns, of these only show the user say 5 of those on startup. but then provide a drop down (or list box etc) of the other column headings, so that when the user selects one... it adds it to the jtable. also to remove ..... is there a way to have a pop-up when the user right-clicks the table header and put a option to remove that column there? if not what is the best way to trigger a remove of a column? So i need a way to keep track of all the columns in case the user wants to add it again. anyone know how this can be done or any part of it?

    I need a intutive way for the user to remove a column from the gui (like with adding could be a dropdown box with column headers as labels).Create a custom ComboBoxModel. This model would simply contain TableColumns and display the header value in the combo box. The first combo box would display the currently showing columns. When you click on an item in the combo box:
    a) remove the TableColumn from the TableColumnModel
    b) remove the TableColumn from the model
    c) add the TableColumn to the "hidden" combo box model
    The same basic logic (but in reverse) would then apply when you click on the "hidden" combo box.

Maybe you are looking for

  • How do I use 2 seperate accounts on 1 computer?

    I purchased a lot of music under my account but now don't know how to synch it to my iPhone as it's stored in the library with all the music from the other account that's used on this laptop....please help

  • Aperture Streaming Problem

    Greetings everyone. So, I've recently purchased and AppleTV and while most everything is turning out perfectly, I'm having a major issue with getting my Aperture photos to stream to the AppleTV and I was hoping that someone here could should some lig

  • SONY ERICSSON DOESNT SUPPORT MAC

    Its REALLY unbelievable. Since i was a child i used to buy all the time SE mobile phones. BUT now it is the last time! I recently bought an iMAC and i tried to tranfer a MOVIE from my MAC to the phone with Media Sync software. (It is the MEdia GO but

  • Report output to be transferred to excel file

    hi all how to transfer the report output to excel file? thanks, kiran.

  • My pc is blocked.how can i unblocked it?

    can someone help me please?my pc is blocked.what should i do to unblocked it?