Jtable without column header

Hi all,
I have searched for jtable without column header... and if it´s possible how can I make?
thanks

Override JTable#configureEnclosingScrollPane() to do nothing or remove the table header manually ( jScrollPane.setColumnHeader(null) ) after you added the table to the scroll pane.

Similar Messages

  • Resize JTable Columns without Column Header

    Hi all.
    I have a JTable that doesn't display a column header.
    I would like to allow the user to resize the columns by dragging a mouse at the column edges at any point down the table.
    It is not obvious how I can accomplish this.
    Does anyone have any ideas?
    Thanks, Paul.

    That doesn't work, though, since the table has its own listenersIt's not just that. The header's mouse listeners work with instance fields of BasicTableHeaderUI and detection (using e.getPoint) of the header cell and column.
    I would start with copying the entire code of BasicTableHeaderUI to a class of my own, then first eliminate anything that obviously isn't related to column dragging/resizing, then refactor, refactor, refactor to make the listener codes work with a table instead of a header. But like I said, easier said than done, particularly when having to deal with the various JTable column resize modes.
    db

  • Resize column width for JTable without column headers?

    Hi,
    I find that for me to resize columns of a JTable by using
    mouse dragging, I MUST have column headers and then drag
    column headers to resize them. Is my understanding correct?
    Actually, I need to have a table without header columns.
    How can I use mouse to resize column width by dragging?
    The background for this request is that I am putting a
    complex table as another table's column header and I hope to
    be able to resizing the complex table by mouse dragging.
    Thanks very much,
    David

    Hi,
    I think you have mistake there. Try
    <style type="text/css">
    table.apexir_WORKSHEET_DATA td {
    white-space:nowrap !important;
    td[headers="DESCR"] {
    width:300px !important;
    max-width:300px !important;
    #apexir_DESCR {
    width:10px;
    max-width:300px !important;
    </style>And you can try add
    table.apexir_WORKSHEET_DATA {
    width: 100% !important;
    table-layout: fixed !important;
    }Regards,
    Jari
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • JTable without column headers?

    I want a JTable without the column headers.
    How can i do this?
    Cheers?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test() {
         String[] head = {"","",""};
         String[][] data = {{"0-0","0-1","0-2"},
                       {"1-0","1-1","1-2"},
                       {"2-0","2-1","2-2"}};
         JTable myTable = new JTable(data,head);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container content = getContentPane();
         content.add(new JScrollPane(myTable), BorderLayout.CENTER);
         setSize(200,200);
         show();
        public static void main(String[] args) { new Test(); }
    }

  • JTable - One Column Heading for Two Columns

    Can you adjust the default JTable to have one column heading for two columns of data? Is there a simple span command? I've looked at the api for JTable and JTableHeader and didn't see anything, is there something I'm missing? Any help would be appreciated.

    What i am trying to accomplish is have column 'E' span 2 columns.
    This is my code thus far, however it give the error from my pryor message. I am pretty sure it is because I'm using and Object[][] and a String[] instead of Vectors. What corrections do I need to make in order for my goal of:
    [ A ][ B ][ C ][ D ][ E  ][ F ][ G ]
    [ 1 ][ 2 ][ 3 ][ 4 ][5][6][ 7 ][ 8 ]
    Object[][] data = new Object[ROWS][COLUMNS];
    String[] columnNames = {"A","B","C","D","E","E","F","G"};
    table = new JTable(data, columnNames);
    table.setBackground(Color.white);
    table.addKeyListener(this);
    DefaultTableCellRenderer d = new DefaultTableCellRenderer();
    d.setHorizontalAlignment(JLabel.CENTER);
    table.setDefaultRenderer(table.getColumnClass(0),d);
    for (int i = 0; i < table.getColumnCount(); i++){
    TableColumn aColumn = header.getColumnModel().getColumn(i);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {
    renderer = new DefaultTableCellRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
    JTableHeader header = table.getTableHeader();
    if (header != null) {
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    setHorizontalAlignment(JLabel.CENTER);
    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
    aColumn.setHeaderRenderer(renderer);

  • JTable howTo: column header = first column??

    Hi,
    i have created a JTable and with the TableColumnModel i have defined column headers. I now would like to have the first column of my table looking the same way like the column headers.
    It shall look similar to what you have in Excel tables: A B C.... = Column headers and 1 2 3 ... = line numbers = first (not editable) column of the table.
    I already tried to write an own table renderer which sets the color equal to the color of the headers but it still looks not equal :-( And there is no TableRowModel, right?
    How can I achieve this appearance?
    Thanks!!!
    Robert

    Here is a simple example to get you started:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=624365

  • Print JTable with column heading

    Hi,
    I'm very new to this JTable. I'm try to print a Jtable using the print() function (from JDK 1.5)
    JTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat(
    _tabledata.getTitle() ),
    new MessageFormat("Page {0,number}"));
    The problem I have is that some time it print and other time it doens't print. Also, if it doesn't print, then the program become very slow or not respond. Is that the probelm with the new JDK or am I doing something wrong?
    Thanks for you help.

    Don't rely on JTable.print() methods too much.
    Sadly Sun didn't think anyone would need to print anything from java so support was added late and half heartedly (programmers hate printing stuff)
    If you are new to java you need to focus on something simpler than printing documents; unfortunatly printing is a tedious burdonsome task for experreineced developers
    for example: learn how to output your data from a table into an HTML formate/file; you can build beautiful reports/printouts easily and view them in java components easily but you will probably want to print them from a browser.
    Even if you find a class or two to help with your printing efforts on the net you will find you need to know many other generic complicated aspects of java to continue
    Sean

  • JTable does not display table column header

    I create a JFrame with a JScrollPane in which I place a mainPanel (=JPanel ) consisting of a leftPanel (=JPanel ) and a rightPanel (=JPanel ). I add to the rightPanel a JTable using constructor JTable(tableModel dm). I overrode method dm.getColumnName(int coulmnIndex) and verified that this method is being invoked. The JTable is being placed in the rightPanel but without column header.

            // Using BorderLayout
            JTable table = new JTable(tableData, tableHeaders);
            add(table, BorderLayout.CENTER);
            add(table.getTableHeader(), BorderLayout.NORTH);

  • Longitudinal table allignment with out column heads

    I need a table should be popup in the new window but without column heads but it consists all the columns one under one in a single column and the corresponding values are in the next column.
    Requirement:
    I have a page consists a table with columns "Acc No, service No, Bill Amt, Older Bills". This older bills column consists a button in its column.
    When ever we click on the button the "Older Bills" page have to be opened with a table automatically populated the Acc No, Service No, 1st mont bill, 2nd month bill, 3rd month bill.All these colums are to be shown in a single column but the values should be shown in the next column.

    Pop up window>> Several old threads which will tell u approach for js window.
    I need a table should be popup in the new window but without column heads
    >>You can give column header promt as null.
    Requirement:
    I have a page consists a table with columns "Acc No, service No, Bill Amt, Older Bills". This older bills column consists a button in its column.
    When ever we click on the button the "Older Bills" page have to be opened with a table automatically populated the Acc No, Service No, 1st mont bill, 2nd month bill, 3rd month bill.All these colums are to be shown in a single column but the values should be shown in the next column.
    >>Have same AM for pop up and base page, so that VO state is shared. In pop up page.... u need to get values from one VO and build another longitudinal table VO .
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem gui_download  -Data looks messy without proper column header

    Dear SDNers,
    Scenario:
    Using FM GUI_download to download excel file to Presentation server.
    Excel file downloads perfecly fine on presentation server with proper column headers when the OS is not XP/Vista.
    Issue:
    when i run this program on my system having Windows Vista,Excel downloads but the column header is all jumbled up without proper differetation.
    Kindly let me know what the the issue could be?
    My Effort:
    I did some googling and found that in Function Modules GUI_DOWNLOAD and GUI_UPLOAD.
    The form of the file name depends on the underlying operating system.
    To make your programs portable to different operating systems, we should use the function module FILE_GET_NAME.
    which returns the system-dependent name for an abstract file name.
    Kindly let me know if this is correct.
    Reason am asking is now i dont have access to code and check the same since i dont have authorization.
    Regards,
    SuryaD.
    Edited by: SuryaD on Jan 12, 2010 2:20 PM

    No response.So closing the thread.

  • JTable - Check box in column header with sorting

    Hello
    I have 3 problems/questions.
    1. When adding sorting to a table with
    setAutoCreateRowSorter(true);and you click on a column header, normally a sorting arrow will appear, and indicate in what direction its sorting,
    but in the column head with the checkbox, even though the sorting works, the arrow will never appear. Is there anyway to fix this?
    2. Is there anyway to get the checkboxes in the table cells to be aligned left (I dont mean the columnheader checkbox, but the ones below)?
    3. When you click on the columnheader to either sort or check the checkbox, you will have to wait about a second between each click, or else it won't react and won't sort. sometimes you will have to click twice for it to react. If you click a lot of times fast, then it won't react until you stop for a second, and click again, though it will react only on the first click, but not the secont, third, fourh, and so on, until you stop for a second. Is there anyway to fix this, or atleast make it have a better reaction time?
    This is the code for creating the table:
    public class Example extends JFrame{
        private Container container;
        private JTable exampleTable;
        public Example(){
            container = getContentPane();
            ExamleTableModel examleTableModel = new ExamleTableModel();
            exampleTable = new JTable(examleTableModel);
            TableColumn tc = exampleTable.getColumnModel().getColumn(0);
            tc.setCellEditor(exampleTable.getDefaultEditor(Boolean.class)); 
            tc.setCellRenderer(exampleTable.getDefaultRenderer(Boolean.class)); 
            tc.setHeaderRenderer(new CheckBoxHeader(new MyItemListener()));
            container.add(new JScrollPane(exampleTable), BorderLayout.SOUTH);
            exampleTable.setAutoCreateRowSorter(true);
            setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );       
            this.pack();
            setSize(500,500);
            setVisible(true);
        }This is the code for the checkboxheader:
        class MyItemListener implements ItemListener 
                public void itemStateChanged(ItemEvent e) { 
                    Object source = e.getSource(); 
                    if (source instanceof AbstractButton == false) return; 
                    boolean checked = e.getStateChange() == ItemEvent.SELECTED; 
                    for(int a = 0, b = exampleTable.getRowCount(); a < b; a++) { 
                        for(int c = 0, d = exampleTable.getRowCount(); c < d; c++) { 
                            if(exampleTable.getColumnName(c).equals("")){
                                exampleTable.setValueAt(new Boolean(checked),a,c);
        class CheckBoxHeader extends JCheckBox 
            implements TableCellRenderer, MouseListener {
            protected CheckBoxHeader rendererComponent; 
            protected int column; 
            protected boolean mousePressed = false; 
            public CheckBoxHeader(ItemListener itemListener) { 
                rendererComponent = this; 
                this.setHorizontalAlignment(JLabel.LEFT);
                rendererComponent.addItemListener(itemListener); 
            public Component getTableCellRendererComponent( 
                    JTable table, Object value, 
                    boolean isSelected, boolean hasFocus, int row, int column) { 
                if (table != null) { 
                    JTableHeader header = table.getTableHeader(); 
                    if (header != null) { 
                        rendererComponent.setForeground(header.getForeground()); 
                        rendererComponent.setBackground(header.getBackground()); 
                        rendererComponent.setFont(header.getFont()); 
                        header.addMouseListener(rendererComponent); 
                setColumn(column); 
                rendererComponent.setText("");
                setBorder(UIManager.getBorder("TableHeader.cellBorder")); 
                return rendererComponent; 
            protected void setColumn(int column){this.column = column;} 
            public int getColumn(){return column;} 
            protected void handleClickEvent(MouseEvent e) { 
                if (mousePressed) { 
                    mousePressed=false; 
                    JTableHeader header = (JTableHeader)(e.getSource()); 
                    JTable tableView = header.getTable(); 
                    TableColumnModel columnModel = tableView.getColumnModel(); 
                    int viewColumn = columnModel.getColumnIndexAtX(e.getX()); 
                    int column = tableView.convertColumnIndexToModel(viewColumn); 
                    if (viewColumn == this.column && e.getClickCount() == 1 && column != -1) { 
                        doClick(); 
            public void mouseClicked(MouseEvent e) { 
                boolean active=true;
                JTableHeader header = (JTableHeader)(e.getSource()); 
                switch (e.getID()) {
                case MouseEvent.MOUSE_CLICKED:
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    JTable tableView = header.getTable();
                    TableColumnModel columnModel = tableView.getColumnModel();
                    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                    int column = tableView.convertColumnIndexToModel(viewColumn);
                    Rectangle bounds = tableView.getCellRect(-1, column, false);
                    if (e.getX() > bounds.x + 16) { // only if one the checkbox
                        if (e.getID() == MouseEvent.MOUSE_CLICKED) {active = false;}
                    }else{active=true;}
                if(active){
                    handleClickEvent(e); 
                    ((JTableHeader)e.getSource()).repaint();   
            public void mousePressed(MouseEvent e){mousePressed = true;} 
            public void mouseReleased(MouseEvent e){} 
            public void mouseEntered(MouseEvent e){} 
            public void mouseExited(MouseEvent e){} 
    }If you want the code for the ExamleTableModel, I will post it if you ask (having trouble with the character limit).

    What are you supposed to cast it to? I might have tried to cast it to something wrong.
    I tried
    TableCellRenderer tcr = table.getDefaultRenderer(Boolean.class);
    ((DefaultTableCellRenderer)tcr).setHorizontalAlignment(SwingConstants.LEFT);and that gave me a ClassCastException. But I might have been trying to cast it to the wrong thing.

  • How to use JButton as a JTable column header?

    I'd like to use JButtons as my JTable's column headers.
    I built a JButton subclass which implemented TableCellRenderer and passed it to one of my table column's setHeaderRender method. The resulting header is a component that looks like a JButton but when clicked, it does not visually depress or fire any ActionEvents.

    You might want to check this example and use it accordingly for your requirements.
    http://www2.gol.com/users/tame/swing/examples/JTableExamples5.html
    Reason: The reason you're unable to perform actions on JButton is JTableHeader doesn't relay the mouse events to your JButtons.
    I hope this helps.
    have fun, ganesh.

  • JTable not displaying column Heads

    The following JPanel was constructed using JBuilder 7 (a horrendous piece of software) and is in GridBagLayout. I'm attempting to display the contents of a table using JTable, and whilst it displays the rows it doesn't display the columnHeads! What am I doing wrong?
    import java.sql.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    public class BeginTask extends JPanel implements ActionListener{
    private boolean dbupdated;
    private MainFrame main;
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JTable jTable1 = new JTable();
    private JButton jButton1 = new JButton();
    private JButton jButton2 = new JButton();
    private GridBagLayout gridBagLayout1 = new GridBagLayout();
    private Connection connection;
    private String url = "jdbc:odbc:bapers";
    private String username = "";
    private String password = "";
    public BeginTask(MainFrame ma) throws SQLException{
    main = ma;
    logon();
    drawTable();
    try {
    jbInit();
    catch(Exception ex) {
    ex.printStackTrace();
    void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
    jLabel1.setText("Begin Task");
    this.setLayout(gridBagLayout1);
    jLabel2.setText("Select Task, and press OK.");
    jButton1.setText("OK");
    jButton2.setText("CANCEL");
    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
    this.add(jButton1, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(12, 117, 14, 0), 94, 8));
    this.add(jButton2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(19, 43, 7, 119), 62, 8));
    this.add(jTable1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 25, 0, 22), 522, 281));
    this.add(jLabel2, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 181, 0, 226), 13, 6));
    this.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(29, 202, 0, 251), 19, 17));
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jButton1) {
    if (dbupdated == true)
    JOptionPane.showMessageDialog(null, "The database has been updated to show that the user has begun the task selected.");
    else if (dbupdated == false)
    JOptionPane.showMessageDialog(null, "The database has not been updated.");
    else if (e.getSource() == jButton2) {
    BapProcMain bpm = new BapProcMain(main);
    main.redisplay(bpm);
    public void logon() {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection(url, username, password);
    catch (ClassNotFoundException cnfex) {
    System.err.println("Failed to load the JDBC/ODBC driver.");
    cnfex.printStackTrace();
    System.exit(1);
    catch (SQLException sqlex) {
    System.err.println("Unable to connect (SQL error)");
    sqlex.printStackTrace();
    public void logoff() {
    if (connection == null) return;
    try { connection.close(); }
    catch (SQLException sqlex) {
    System.err.println("Unable to disconnect (SQL error)");
    public void drawTable() {
    Statement stmt;
    ResultSet rset;
    try {
    String query = "SELECT * FROM SpecificTask";
    stmt = connection.createStatement();
    rset = stmt.executeQuery(query);
    displayResultSet(rset);
    stmt.close();
    catch (SQLException sqlex) {
    sqlex.printStackTrace();
    private void displayResultSet(ResultSet rs) throws SQLException {
    // position to first record
    boolean moreRecords = rs.next();
    // if there are no records, display a message
    if (! moreRecords){
    JOptionPane.showMessageDialog (this, "No Specific Tasks to begin.");
    return;
    Vector columnHeads = new Vector();
    Vector rows = new Vector();
    try {
    // get column heads
    ResultSetMetaData rsmd = rs.getMetaData();
    for (int i = 1; i <= rsmd.getColumnCount(); ++i)
    columnHeads.addElement (rsmd.getColumnName(i));
    //get row data
    // System.out.println("Got this far. Check getNextRow(...)");
    do { rows.addElement(getNextRow(rs, rsmd)); }
    while (rs.next());
    // display table with ResultSet contents
    jTable1 = new JTable (rows, columnHeads);
    JScrollPane scroller = new JScrollPane(jTable1);
    // validate();
    catch (SQLException sqlex) {
    sqlex.printStackTrace();
    private Vector getNextRow (ResultSet rs, ResultSetMetaData rsmd) throws SQLException {
    Vector currentRow = new Vector();
    for (int i = 1; i <= rsmd.getColumnCount(); ++ i)
    switch (rsmd.getColumnType(i)) {
    case Types.VARCHAR:
    currentRow.addElement(rs.getString(i));
    break;
    case Types.INTEGER:
    currentRow.addElement(new Long (rs.getLong(i) ) );
    break;
    default: System.out.println ("Type was: " +
    rsmd.getColumnTypeName(i));
    return currentRow;
    }

    The table header is shown automatically when you add the table to a scrollpane and then display the scrollpane in a panel. You use the following code to build the table/scrollpane:
    // display table with ResultSet contents
    jTable1 = new JTable (rows, columnHeads);
    JScrollPane scroller = new JScrollPane(jTable1);
    but, you add the table to your panel NOT the scrollpane:
    this.add(jTable1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 25, 0, 22), 522, 281));
    You should be adding the scrollpane to you panel.

  • How to Freeze Table/Column Header "without using additional scrollbars" ?

    hi people,
    I am hoping someone can help me here. I have a large table and would like to freeze the first row. Scrolling down the table "_*using the existing scrollbars*_" in the browser while ensuring the header rows are still visible (like Excel when you freeze panes). If you scroll to the right the header rows should stay frozen and not follow.
    I know there are other threads which talk about freezing table/column header, but my requirement is to have it "without using additional scrollbar".
    Thanks in advance,
    RAKESH

    Hi,
    there is no default key for this. You will have to code your own JavaScript for this. Also, I am not sure you want the column to be selected but a field in the column for the row you are in - correct ?
    Frank

  • Adding mouse listener to the column header of a column in a JTable

    Hi
    I want to add a mouse listener to the column header of the 3rd column in a JTable. I dont find any appropriate method to do this. The code I have written to do this is below. But on using this code, the mouselistener is invoked if I click on any column header. Can anyone please help me to fix this.
    table.getTableHeader().addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    /* some actions */
    }

          table.getTableHeader().addMouseListener(new MouseAdapter(){
               public void mousePressed(MouseEvent me) {
                   int tableColumn  =table.columnAtPoint(me.getPoint());//it returns the column index
            });

Maybe you are looking for