JTableHeader + columns

Hello to all!!!!!
I speak spanish
I am working with a jTable in which the idea is to take information from a DB and to show it by this component. But it is that the columns of the table can be changed of position and be changed the size of them. So that this does not happen I read in the API in the JTableHeader class the methods setReorderingAllowed() and setResizingAllowed() which handle this, but I can?t to know, of how they are used since I have proven several forms and throws errors, this is what I make:
TableModel dataModel = new AbstractTableModel() {
final String[ ] columnNames = { "Name", "Last name", "Pastime", "Years of Practices", "Soltero(a)" };
Object[][ end ] dates = {
{ "Mary", "Campione"," To ski ", new Integer(5), new Boolean(false) },
{ "Lhucas", "Huml"," To slide ", new Integer(3), new Boolean(true) },
{ "Kathya", "Walrath"," To climb ", new Integer(2), new Boolean(false) },
{ "Marcus", "Andrews"," To run ", new Integer(7), new Boolean(true) },
{ "Angela", "Lalth"," To swim ", new Integer(4), new Boolean(false) } };
public int getColumnCount() { return columnNames.length; }
public int getRowCount() { return data.length; }
public String getColumnName(int col) { return columnNames[col ]; }
public Object getValueAt(int row, int col) { return data[row][col ]; }
public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); }
JTable jTable1 = new JTable(dataModel);
JTableHeader to tableheader = jTable1.getTableHeader(); tableheader.setReorderingAllowed(false);
JScrollPane jScrollPane1 = JTable.createScrollPaneForTable(jTable1);
and the other form is to change:
JTableHeader to tableheader = jTable1.getTableHeader(); tableheader.setReorderingAllowed(false);
By:
jTable1.getTableHeader().setReorderingAllowed(false);
With first it throws the following error to me:
invalid method declaration; return type required and illegal start of type.
With second form: malformed passes + the same expression.
In addition, I am working with JBuilder2, that comes with JDK 1.1
How work these metodos and the JTableHeader class, Will be problem of my JDK of which it does not allow east type me of declarations? Why it throws these errors to me? Who me can throw a hand, beforehand many thanks.

I attempted to use Darryl's Default Table Header Cell Renderer, but I was unable (it requires java 1.6).
I modified the code to make a very simple renderer. It does the job apropriately, but the header cell does not change its color (to red or white) unless the window is resized. Here is my very simple renderer (based on Darryl's one). What am I missing now?
Thanks once more,
Federico
public class MyDefaultTableHeaderCellRenderer extends DefaultTableCellRenderer {
     public String jorl = "hola";
     public boolean tmp = false;
     public MyDefaultTableHeaderCellRenderer() {
          setHorizontalAlignment(CENTER);
          setHorizontalTextPosition(LEFT);
          setOpaque(true);
     public Component getTableCellRendererComponent(JTable table, Object value,
                                                               boolean isSelected, boolean hasFocus, int row, int column) {
          super.getTableCellRendererComponent(table, value,
                                                       isSelected, hasFocus, row, column);
          if(table.isColumnSelected(column)) {
               setBackground(java.awt.Color.red.darker());
          } else {
               setBackground(java.awt.Color.white);
          setBorder(UIManager.getBorder("TableHeader.cellBorder"));
          return this;
}

Similar Messages

  • Selecting a column in the JTableHeader

    Hi all,
    I am currently working on an application where the user (by d n' d or cut n' paste) should be able to add data to a table. It works fine to add data to the table and display it by using a renderer, but it seems to be impossible to add data to the header. The header won't get selected when clicking on it (and thus never receives the focus...). I have tried various ways of using mouse listeners, overriding the isFocusTraversable() in JTableHeader, setting table.setColumnSelectionAllowed(true), and header.setRequestFocusEnabled(true), but nothing is working. How on earth can I select a column header?

    You definitely will have to roll your own: as is JTableHeader does not support the notion of selection.
    To do so, you will need to change several things:
    1. make the XXTableHeaderUI aware of selection (it always sends false for both isSelected and hasFocus when it repaints the renderer)
    2. have a custom headerRenderer that respects the flags selected/focus
    3. make some object responsible for sending notification if the value for the columnHeader does change - as is the columnNames are stored in the TableModel, but nothing happens when they are changed; so easiest would be to make a customTableModel responsible for firing some event.
    4. make the header listen to the changes.
    As you see, it's quite involved. Good luck
    Jeanette

  • How can I make a JTable wider than the cumulation of its columns??

    I have a JTable that overrides tableChanged to modify its size based on how many rows and columns it has and adding 16 pixels. Everything works great with adding 16 pixels to the bottom of my table, but when I try to add 16 pixels to the right side, the columns grow to fill the space even though I have AUTO_RESIZE_OFF.
    I want there to be 16 pixels between the edge of my last column and the edge of the scroll pane when I have scrolled all the way to the right.
    Does anybody know how to do this?? I have been messing with it for hours!
    Tonya
    P.S. Here is the code so far:
         class AlgoResultsSpreadsheetTable extends JTable {
              AlgoResultsSpreadsheetTable() {
                   super();
                   setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                   setOpaque(false);
              public void tableChanged(TableModelEvent e) {
                   super.tableChanged(e);
                   setMinimumSize(new Dimension((getColumnCount() * 75) + 16,
                             (getRowCount() + 1) * 16));
                   setPreferredSize(new Dimension((getColumnCount() * 75) + 16,
                             (getRowCount() + 1) * 16));
                   JTableHeader header = getTableHeader();
                   header.setPreferredSize(
                             new Dimension((getColumnCount() * 75) + 16, 200));
         }

    Nevermind... I just figured it out:
                   Enumeration<TableColumn> enu = getColumnModel().getColumns();
                   while (enu.hasMoreElements()) {
                        TableColumn column = enu.nextElement();
                        column.setPreferredWidth(75);
                        column.setMaxWidth(75);
                        column.setResizable(false);
                   }

  • Column size and number of chars

    I have fixed Jtables column header size.
    when I put a large text in this colums ,half of text is hidden. I know this problem is solved with setAutoResizeMode, bat I don't wont to use it.
    I wont to know how many chars can I put in this column(with fixed size),
    How can I return number Of chars or length or text which can be possible tu put fixed columean size?

    Well, you can do something like (untested)
    TableColumnModel tcm = table.getColumnModel();
    TableColumn col = tcm.getColumn( n );
    int cw = col.getMaxWidth();
    String st = col.getHeaderValue().toString();
    JTableHeader header = table.getTableHeader();
    FontMetrics fm = header.getFontMetrics( header.getFont() );
    for( int sw = fm.stringWidth( st ); sw > cw; ) {
         st = st.substring( 0, st.length()-1 );
         sw = fm.stringWidth( st );
    col.setHeaderValue( st );That should at least give you some ideas.

  • 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 in JPanel last Column resize clips JTable doesnt repaint JPanel

    I have a JTable in a JPanel, when I drag the last column of the JTableHeader (u can see the column resizing as the text of the Table HeaderColumn moves with the drag) the JTable is outside the JPanel. Only when u click on another component and then click back on the JTableHeader does it repaint.
    I have tried jPanel.revalidate(); in the mouseDragged event of MouseMotionListener on the JTableHeader and all manner or repaints and fireTableStructureChanged. But I dont understand the order of events.
    The last bug to fix!!!
    NB I dont want to use scrollpane as its not necessary and as many tables are synchronized with one table it makes repaints less smooth
    Thanks Paul

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • Resize JTable columns by double-clicking header

    I want to implement column resizing in a JTable so that when the user double clicks on the column header with the mouse in the "resize zone" the column automatically adjusts to the width of the longest text in the column. this is how many applications behave (e.g. windows explorer) but I don't think I've ever seen a swing app that does this. I've looked in the API docs for JTable and JTableHeader and I can't see any way of finding out if the mouse is over the edge of a column header. does anyone know of a way to do this?

    Is this laf independant?import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Test extends JFrame {
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One","Two","Three"};
        String[][] data = {{"R1-C1","R1-C2","R1-C3"},
                {"R2-C1","R2-C2","R2-C3"},
                {"R3-C1","R3-C2","R3-C3"}};
        JTable jt = new JTable(data, head);
        JScrollPane jsp = new JScrollPane(jt);
        content.add(jsp, BorderLayout.CENTER);
        JTableHeader jth = jt.getTableHeader();
        jth.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            JTableHeader jth = (JTableHeader)me.getSource();
            int col = jth.columnAtPoint(me.getPoint());
            Rectangle r = jth.getHeaderRect(col);
            if (jth.getCursor().equals(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR))) {
              System.out.println("Cursor, col="+col);
        setSize(300, 300);
        setVisible(true);
      public static void main(String args[]) { new Test(); }
    }

  • Problem with JTableHeader Render

    Hello,
    I am using JTableHeader renderer as below:
    TableHeaderRender headerRender;
    fixedModel.addColumn("");
                   TableColumnModel colModel = Table.getColumnModel();
                   for(int i=0; i<colModel.getColumnCount(); i++ )
                        colModel.getColumn(i).setHeaderRenderer(headerRender);
    And the renderer is as below:
    class FixedTableHeaderRender extends DefaultTableCellRenderer
              JLabel label = null;
              String[] selectList= {"Item1","item 2", Item 3", "Item 4"};
              JComboBox ColStatBox= new JComboBox(selectList);
    public FixedTableHeaderRender()
    super();
    label = new JLabel();
    label.setOpaque(true);
    label.setBorder(new LineBorder(Color.black));
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setVerticalAlignment(SwingConstants.CENTER);
    ColStatBox.setSelectedIndex(0);
    ColStatBox.setEnabled(true);
    ColStatBox.setAutoscrolls(true);
    ColStatBox.addActionListener(new ActionHandler(){
    public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected,boolean hasFocus, int row,int column)
         Component comp= null;
         if(column==0)
              comp=ColStatBox;
         else
              label.setText("100");
              comp=label;
         return comp;
    Now in this for First column header the JComboBox is displayed and for rest of the column the label is displayed.
    But in this, the JComboBox is not working i.e. I am not able the browse through the list. If I want to select any item (Item 4), its not allowing me to select.
    How to make it enable and function normally?
    Do reply.
    Thanks and regards,
    Sheetal

    I've amended your code as shown. Some points:
    1) Not sure what all the scroll bar stuff is for, I've removed it.
    2) The method DefaultTableModel.addColumn is too crude. If you look at the JDK source it calls fireTableStructureChanged(). This has the effect of recreating the column model, which in turn resets all the widths. It will also clear out any renderers/editors you had set up within the TableColumn instances inside the TableColumnModel (if any). Those setup by column class would be OK (I think).
    I didn't look into the remainder of your problem, hopefully you are OK now...
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.*;
    import javax.swing.table.DefaultTableModel;
    public class MyJTable extends JFrame
    DefaultTableModel model;
    JButton addBtn;
    JTable table;
    JScrollBar scrollBar;
    JScrollPane scrollPane;
         public MyJTable()
              getContentPane().setLayout(new BorderLayout());
              Object[] header= {"1", "2"};
              model= new DefaultTableModel();
              model.setDataVector(null,header);
               table = new JTable(model);
               table.getTableHeader().setReorderingAllowed(false);
               table.getTableHeader().setResizingAllowed(true);
               table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
               scrollBar=new JScrollBar();
              scrollBar.setOrientation(1);
              scrollBar.setBlockIncrement(1);
              scrollBar.setMinimum(0);
              scrollBar.setMaximum(50);
              scrollBar.setUnitIncrement(1);
              scrollBar.setVisibleAmount(1);
              table.add(scrollBar);
              scrollPane=new JScrollPane(table);
              scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
               addBtn=new JButton("Add Column");
               addBtn.addActionListener(new ActionHandler());
               getContentPane().add(scrollPane, BorderLayout.CENTER);
               getContentPane().add(addBtn, BorderLayout.SOUTH);
         class ActionHandler implements ActionListener
              //@Override
              public void actionPerformed(ActionEvent ae)
                   // TODO Auto-generated method stub
                   if(ae.getSource()==addBtn)
                        //model=(DefaultTableModel)table.getModel();
                        //model.addColumn("A");
                        //model.fireTableStructureChanged();
                        TableColumnModel tcm = table.getColumnModel();
                        TableColumn newCol = new TableColumn();
                        newCol.setHeaderValue("A");
                        tcm.addColumn(newCol);
          * @param args
         public static void main(String[] args)
              MyJTable frame = new MyJTable();
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  frame.setSize( 300, 400 );
                  frame.setVisible(true);
    }

  • Custom column headers for JTable in JScrollPane

    I want a heirachical header structure on a scrolled JTable. I've successfully generated a second JTableHeader which moves it's tabs with the normal header. If I add the secondary JTableHeader into the container above the whole scroll pane it's does almost what I want, but it's not quite correctly aligned.
    What I want to do is to put both the automaticaly generated JTableHeader and my extra one into the JScrollPane's column header area.
    I wrapped the two headers together into a vertical Box and tried calling the setColumnHeaderView() on the scrollpane, and then creating a JViewport and using setColumnHeader(). Niether seems to have any effect. The basic table header obstinately remains unaltered.
    There seems to be some special processing going on when JTable and JScrollPane get together, but I can't understand how replacing the column header viewport can be ineffective.

    Thanks. I think I've just cracked it more thoroughly, though. [I found this bug report|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5032464]. This has guided me to a work-around that seems stable so far. I'm using an extended JTable class anyway (mostly to do with table header width behaviour). I've added a field to my own table class and the following override:
    The trick is to work out where the dirty deed is done, having search all the scroll pane related classes for special casing JTable.
    public class STable extends JTable {
        @Override
        protected void configureEnclosingScrollPane() {
            if (secondaryHeader == null) {
                super.configureEnclosingScrollPane();
            } else {
                Container p = getParent();
                if (p instanceof JViewport) {
                    Container gp = p.getParent();
                    if (gp instanceof JScrollPane) {
                        JScrollPane scrollPane = (JScrollPane) gp;
                        // Make certain we are the viewPort's view and not, for
                        // example, the rowHeaderView of the scrollPane -
                        // an implementor of fixed columns might do this.
                        JViewport viewport = scrollPane.getViewport();
                        if (viewport == null || viewport.getView() != this) {
                            return;
                        JPanel hdrs = new JPanel();
                        hdrs.setLayout(new BorderLayout());
                        hdrs.add(secondaryHeader.getHeader(), BorderLayout.NORTH);
                        hdrs.add(getTableHeader(), BorderLayout.SOUTH);
                        scrollPane.setColumnHeaderView(hdrs);
                        //  scrollPane.getViewport().setBackingStoreEnabled(true);
                        Border border = scrollPane.getBorder();
                        if (border == null || border instanceof UIResource) {
                            Border scrollPaneBorder =
                                    UIManager.getBorder("Table.scrollPaneBorder");
                            if (scrollPaneBorder != null) {
                                scrollPane.setBorder(scrollPaneBorder);
        }I'm hopeful that will prevent the column header view from being overwritten by later layout operations.

  • 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.

  • My final version of a table with row headers and column footers

    This version is superior to the one I posted yesterday
    as it is better designed and responds to changes in
    size correctly. You can also have a header/footer with
    multiple columns/rows.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.TableColumnModel;
    import java.awt.*;
    import java.awt.event.AdjustmentListener;
    import java.awt.event.AdjustmentEvent;
    import java.awt.event.ComponentListener;
    import java.awt.event.ComponentEvent;
    public class HeaderFooterTablePanel extends JPanel {
        static abstract class AbstractHeaderFooterTableModel extends AbstractTableModel {
            public abstract int getRowHeaderColumnCount();
            public abstract Object getRowHeaderValueAt(int rowIndex,
                                                       int columnIndex);
            public abstract int getFooterRowCount();
            public abstract Object getFooterValueAt(int rowIndex,
                                                    int columnIndex);
        static class RowHeaderTableModel extends AbstractTableModel {
            private AbstractHeaderFooterTableModel abstractHeaderFooterTableModel;
            public RowHeaderTableModel(AbstractHeaderFooterTableModel abstractHeaderFooterTableModel) {
                super();
                this.abstractHeaderFooterTableModel = abstractHeaderFooterTableModel;
            public String getColumnName(int column) {
                return "";
            public int getColumnCount() {
                return abstractHeaderFooterTableModel.getRowHeaderColumnCount();
            public int getRowCount() {
                return abstractHeaderFooterTableModel.getRowCount();
            public Object getValueAt(int rowIndex, int columnIndex) {
                return abstractHeaderFooterTableModel.getRowHeaderValueAt(rowIndex, columnIndex);
        static class ColumnFooterTableModel extends AbstractTableModel {
            private AbstractHeaderFooterTableModel abstractHeaderFooterTableModel;
            public ColumnFooterTableModel(AbstractHeaderFooterTableModel abstractHeaderFooterTableModel) {
                super();
                this.abstractHeaderFooterTableModel = abstractHeaderFooterTableModel;
            public String getColumnName(int column) {
                return "";
            public int getColumnCount() {
                return abstractHeaderFooterTableModel.getColumnCount();
            public int getRowCount() {
                return abstractHeaderFooterTableModel.getFooterRowCount();
            public Object getValueAt(int rowIndex, int columnIndex) {
                return abstractHeaderFooterTableModel.getFooterValueAt(rowIndex, columnIndex);
        static class SyncColumnWidths implements TableColumnModelListener {
            private final JTable centerTable;
            private final JTable footerTable;
            public SyncColumnWidths(JTable centerTable,
                                    JTable footerTable) {
                this.centerTable = centerTable;
                this.footerTable = footerTable;
            // Change the column widths of the footer table when the column widths
            // of the center table change.
            public void columnMarginChanged(ChangeEvent e) {
                TableColumnModel centerTableColumnModel = centerTable.getColumnModel();
                TableColumnModel footerTableColumnModel = footerTable.getColumnModel();
                for (int i = 0; i < centerTableColumnModel.getColumnCount(); i++) {
                    int width = centerTableColumnModel.getColumn(i).getPreferredWidth();
                    footerTableColumnModel.getColumn(i).setPreferredWidth(width);
            public void columnSelectionChanged(ListSelectionEvent e) {
            public void columnAdded(TableColumnModelEvent e) {
            public void columnMoved(TableColumnModelEvent e) {
            public void columnRemoved(TableColumnModelEvent e) {
        private JTable centerTable;
        private JTable rowHeaderTable;
        private JTable columnFooterTable;
        public HeaderFooterTablePanel(AbstractHeaderFooterTableModel abstractHeaderFooterTableModel) {
            super();
            // Create the center, rowHeader and columnFooter tables
            centerTable = new JTable(abstractHeaderFooterTableModel);
            rowHeaderTable = new JTable(new RowHeaderTableModel(abstractHeaderFooterTableModel));
            columnFooterTable = new JTable(new ColumnFooterTableModel(abstractHeaderFooterTableModel));
            // Disabled column re-ordering
            centerTable.getTableHeader().setReorderingAllowed(false);
            columnFooterTable.getTableHeader().setReorderingAllowed(false);
            // We are using scroll panes, so no auto resizing of table.
            centerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            columnFooterTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            // Only allow the user to change the column widths from the center table, not the
            // columnFooter.
            columnFooterTable.getTableHeader().setResizingAllowed(false);
            // When the center table column widths change, change those in the columnFooter table.
            SyncColumnWidths syncColumnWidths = new SyncColumnWidths(centerTable, columnFooterTable);
            centerTable.getColumnModel().addColumnModelListener(syncColumnWidths);
            // Set the width of the row header before adding it to the center scroll pane
            // as the row header.
            Dimension rowHeaderSize = rowHeaderTable.getPreferredScrollableViewportSize();
            rowHeaderSize.width = rowHeaderTable.getPreferredSize().width;
            rowHeaderTable.setPreferredScrollableViewportSize(rowHeaderSize);
            rowHeaderTable.setRowHeight(centerTable.getRowHeight());
            // Create the center scroll pane and set the row header table as the row header.
            final JScrollPane centerScrollPane = new JScrollPane(centerTable);
            centerScrollPane.setRowHeaderView(rowHeaderTable);
            // We will handle horizontal scrolling with our own scrollbar.
            centerScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            // Now we create the panel to hold the columnFooter table and the horizontal
            // scrollbar.
            final JPanel columnFooterPanel = new JPanel(new BorderLayout());
            // Keep the space below the row header empty.
            Component westGlue = Box.createHorizontalStrut(rowHeaderSize.width);
            // Set height of the columnFooterTable before adding it to the columnFooter scroll pane
            // as the view.
            Dimension columnFooterSize = columnFooterTable.getPreferredScrollableViewportSize();
            columnFooterSize.height = columnFooterTable.getPreferredSize().height;
            columnFooterTable.setPreferredScrollableViewportSize(columnFooterSize);
            columnFooterTable.setRowHeight(centerTable.getRowHeight());
            // The scroll pane which holds the columnFooterTable.
            final JScrollPane columnFooterScrollPane = new JScrollPane(columnFooterTable);
            // We do our own horizontal scrolling and the columnFooterScrollPane never scrolls vertically.
            columnFooterScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            columnFooterScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
            // The scrollbar we use to scroll horizontally.
            final JScrollBar horizontalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
            // Sync up all the scrolling. See the method for details.
            syncScrolling(centerScrollPane, horizontalScrollBar, columnFooterScrollPane);
            // Keep the space below the vertical scrollbar empty.
            final JScrollBar verticalScrollBar = centerScrollPane.getVerticalScrollBar();
            int verticalScrollBarWidth = verticalScrollBar.getPreferredSize().width;
            final Component eastGlue = Box.createHorizontalStrut(verticalScrollBarWidth);
            // Set the center viewport size to match to table size
            Dimension centerTablePreferredsize = centerTable.getPreferredSize();
            centerTable.setPreferredScrollableViewportSize(centerTablePreferredsize);
            centerScrollPane.getViewport().setSize(centerTablePreferredsize);
            // The panel that holds the columnFooterTable and the horizontal scrollbar below it.
            final JPanel footerPanel = new JPanel(new BorderLayout());
            footerPanel.add("North", columnFooterScrollPane);
            footerPanel.add("South", horizontalScrollBar);
            footerPanel.setMinimumSize(footerPanel.getPreferredSize());
            // Assemble our columnFooterPanel.
            columnFooterPanel.add("West", westGlue);
            columnFooterPanel.add("Center", footerPanel);
            columnFooterPanel.add("East", eastGlue);
            // This keeps the columnFooterPanel at its minimum height
            JPanel northPanel = new JPanel(new BorderLayout());
            northPanel.add("North", columnFooterPanel);
            // Assemble the center scroll pane, below it the panel containing the column
            // footer panel, and then vertical glue to eat up any available vertical space.
            Box box = Box.createVerticalBox();
            box.add(centerScrollPane);
            box.add(northPanel);
            box.add(Box.createVerticalGlue());
            // Hide/show the eastGlue and the horizontalScrollBar, and recalculate the
            // minimum size of the footerPanel in response to size and visibility changes.
            syncScrollBarVisibility(centerScrollPane, eastGlue, horizontalScrollBar, footerPanel);
            setLayout(new BorderLayout());
            add("Center", box);
        private void syncScrollBarVisibility(final JScrollPane centerScrollPane,
                                             final Component eastGlue,
                                             final JScrollBar horizontalScrollBar,
                                             final JPanel footerPanel) {
            // Hide/show the eastGlue accoring to whether or not the vertical scrollbar
            // is visible.
            centerScrollPane.getVerticalScrollBar().addComponentListener(new ComponentListener() {
                private void checkVisibleStatus(boolean b) {
                    if (eastGlue.isVisible() != b) {
                        eastGlue.setVisible(b);
                public void componentHidden(ComponentEvent e) {
                    checkVisibleStatus(false);
                public void componentMoved(ComponentEvent e) {
                public void componentResized(ComponentEvent e) {
                public void componentShown(ComponentEvent e) {
                    checkVisibleStatus(true);
            // Hide/show the horizontal scrollbar according to whether or not it's needed.
            centerScrollPane.getViewport().addComponentListener(new ComponentListener() {
                public void componentHidden(ComponentEvent e) {
                public void componentMoved(ComponentEvent e) {
                public void componentResized(ComponentEvent e) {
                    int centerScrollPaneWidth = centerScrollPane.getViewport().getSize().width;
                    int centerTablePreferredWidth = centerTable.getPreferredSize().width;
                    if (centerScrollPaneWidth >= centerTablePreferredWidth) {
                        horizontalScrollBar.setVisible(false);
                    } else {
                        horizontalScrollBar.setVisible(true);
                public void componentShown(ComponentEvent e) {
            // Set the minimum size of the footerPanel according to whether or not the
            // horizontalScrollBar is visible.
            horizontalScrollBar.addComponentListener(new ComponentListener() {
                public void componentHidden(ComponentEvent e) {
                    footerPanel.setMinimumSize(footerPanel.getPreferredSize());
                public void componentMoved(ComponentEvent e) {
                public void componentResized(ComponentEvent e) {
                public void componentShown(ComponentEvent e) {
                    footerPanel.setMinimumSize(footerPanel.getPreferredSize());
        private void syncScrolling(final JScrollPane centerScrollPane,
                                   final JScrollBar columnFooterScrollBar,
                                   final JScrollPane columnFooterScrollPane) {
            // When the view of the center scroll pane changes position,
            // change the value of the columnFooterScrollBar to match.
            centerScrollPane.getViewport().addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    int x = ((Component) e.getSource()).getLocation().x * -1;
                    JViewport viewport = (JViewport) e.getSource();
                    int extentWidth = viewport.getExtentSize().width;
                    int viewWidth = viewport.getViewSize().width;
                    int value = Math.max(0, Math.min(viewport.getViewPosition().x, viewWidth - extentWidth));
                    columnFooterScrollBar.setValues(value, extentWidth, 0, viewWidth);
            // When the columnFooterScrollBar (horizontal scroll bar) value changes,
            // change the position of the view in the center scroll pane to match.
            columnFooterScrollBar.addAdjustmentListener(new AdjustmentListener() {
                public void adjustmentValueChanged(AdjustmentEvent e) {
                    JViewport viewport = centerScrollPane.getViewport();
                    viewport.setViewPosition(new Point(e.getValue(), viewport.getViewPosition().y));
                    viewport = columnFooterScrollPane.getViewport();
                    viewport.setViewPosition(new Point(e.getValue(), viewport.getViewPosition().y));
            // When the view of the row header changes position,
            // change the value of the vertical scrollbar of the center
            // scroll pane to match.
            centerScrollPane.getRowHeader().addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    JViewport viewport = (JViewport) e.getSource();
                    int extentHeight = viewport.getExtentSize().height;
                    int viewHeight = viewport.getViewSize().height;
                    int value = Math.max(0, Math.min(viewport.getViewPosition().y, viewHeight - extentHeight));
                    centerScrollPane.getVerticalScrollBar().setValues(value, extentHeight, 0, viewHeight);
        public JTable getCenterTable() {
            return centerTable;
        public JTable getRowHeaderTable() {
            return rowHeaderTable;
        private JTable getColumnFooterTable() {
            return columnFooterTable;
        public static void main(String[] args) {
            AbstractHeaderFooterTableModel tableModel = new AbstractHeaderFooterTableModel() {
                public int getRowCount() {
                    return 25;
                public int getColumnCount() {
                    return 10;
                public Object getValueAt(int rowIndex, int columnIndex) {
                    return "Cell " + rowIndex + ":" + columnIndex;
                public String getColumnName(int column) {
                    return "Column #" + column;
                public Object getRowHeaderValueAt(int rowIndex, int columnIndex) {
                    return "Header " + rowIndex + ":" + columnIndex;
                public int getRowHeaderColumnCount() {
                    return 2;
                public Object getFooterValueAt(int rowIndex, int columnIndex) {
                    return "Footer " + rowIndex + ":" + columnIndex;
                public int getFooterRowCount() {
                    return 3;
            JFrame frame = new JFrame();
            HeaderFooterTablePanel tablePanel = new HeaderFooterTablePanel(tableModel);
            // Render the cells in the row header and footer like the center table column headers.
            TableCellRenderer columnRenderer = tablePanel.getCenterTable().getTableHeader().getDefaultRenderer();
            tablePanel.getRowHeaderTable().setDefaultRenderer(Object.class, columnRenderer);
            tablePanel.getColumnFooterTable().setDefaultRenderer(Object.class, columnRenderer);
            frame.getContentPane().add("Center", tablePanel);
            frame.setSize(300, 300);
            frame.setLocation(300, 200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }

    i was wondering why this topic has NO replies! and then i realized that there is NO question??? so do you have a question, or are you just starting a new thread cuz you feel like it???
    just trying to work out why you didnt post this is the old thread???
    http://forum.java.sun.com/thread.jspa?threadID=5130131&messageID=9466400#9466400

  • How to freeze row and column in JTable

    Hi,
    I need to freeze first two rows and columns in a large JTable. I found ways to freeze either a row or a column, but not both at the same time.
    Can any of you help ?
    Found this code which allows freezing a col. Similar method can be used to freeze column
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JViewport;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableModel;
    public class FrozenTablePane extends JScrollPane{
    public FrozenTablePane(JTable table, int colsToFreeze){
    super(table);
    TableModel model = table.getModel();
    //create a frozen model
    TableModel frozenModel = new DefaultTableModel(
    model.getRowCount(),
    colsToFreeze);
    //populate the frozen model
    for (int i = 0; i < model.getRowCount(); i++) {
    for (int j = 0; j < colsToFreeze; j++) {
    String value = (String) model.getValueAt(i, j);
    frozenModel.setValueAt(value, i, j);
    //create frozen table
    JTable frozenTable = new JTable(frozenModel);
    //remove the frozen columns from the original table
    for (int j = 0; j < colsToFreeze; j++) {
    table.removeColumn(table.getColumnModel().getColumn(0));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //format the frozen table
    JTableHeader header = table.getTableHeader();
    frozenTable.setBackground(header.getBackground());
    frozenTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    frozenTable.setEnabled(false);
    //set frozen table as row header view
    JViewport viewport = new JViewport();
    viewport.setView(frozenTable);
    viewport.setPreferredSize(frozenTable.getPreferredSize());
    setRowHeaderView(viewport);
    setCorner(JScrollPane.UPPER_LEFT_CORNER, frozenTable.getTableHeader());
    }

    Hi,
    I need to freeze first two rows and columns in a large JTable. I found ways to freeze either a row or a column, but not both at the same time.
    Can any of you help ?
    Found this code which allows freezing a col. Similar method can be used to freeze column
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JViewport;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableModel;
    public class FrozenTablePane extends JScrollPane{
    public FrozenTablePane(JTable table, int colsToFreeze){
    super(table);
    TableModel model = table.getModel();
    //create a frozen model
    TableModel frozenModel = new DefaultTableModel(
    model.getRowCount(),
    colsToFreeze);
    //populate the frozen model
    for (int i = 0; i < model.getRowCount(); i++) {
    for (int j = 0; j < colsToFreeze; j++) {
    String value = (String) model.getValueAt(i, j);
    frozenModel.setValueAt(value, i, j);
    //create frozen table
    JTable frozenTable = new JTable(frozenModel);
    //remove the frozen columns from the original table
    for (int j = 0; j < colsToFreeze; j++) {
    table.removeColumn(table.getColumnModel().getColumn(0));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //format the frozen table
    JTableHeader header = table.getTableHeader();
    frozenTable.setBackground(header.getBackground());
    frozenTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    frozenTable.setEnabled(false);
    //set frozen table as row header view
    JViewport viewport = new JViewport();
    viewport.setView(frozenTable);
    viewport.setPreferredSize(frozenTable.getPreferredSize());
    setRowHeaderView(viewport);
    setCorner(JScrollPane.UPPER_LEFT_CORNER, frozenTable.getTableHeader());
    }

  • Hide a column in a JTable

    Hi All, hope you can help,
    I want to hide the last column of my table, but still access its data. Inside the last column certain information is present, the cell tooltips.
    In my extended JTable class my method getToolTipText looks like this:
            // implement table cell tool tip.
            public String getToolTipText(MouseEvent e) {
                String tip             = null;
                Point  p               = e.getPoint();
                int    rowIndex        = rowAtPoint(p);
                int    colIndex        = columnAtPoint(p);
                int    realColumnIndex = convertColumnIndexToModel(colIndex);
                if(rowIndex>=0 && rowIndex<=lastRow) {
                    if(realColumnIndex==0) {
                        MiniModel mml = (MiniModel)getValueAt(rowIndex, 5); // exception here
                        tip = "<html>" + replaceCRLFtoBR(mml.getComment()) + "</html>"; // replaceCRLFtoBR = custom method to replace \n by <br>
                    } else {
                        tip = columnTips[realColumnIndex]; // constant
                return tip;
            }As you can see at column 5 an object MiniModel is present containing the tooltip for column 0.
    When I use the method removeColumn on column 5 on my extended JTable variable, I get an java.lang.ArrayIndexOutOfBoundsException at the marked position and in more detail on getValueAt.
    As I read everywhere the actual data is not removed (only from the view) I wonder what I'm doing wrong...
    Michiel

    Thanks for the advice, I will prepare better next time, here is my sscce :
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    public class TableHide extends JFrame {
        private static final String[] colNames    = {"Column 1", "Column 2", "Column 3"};
        private static final String[] colHeadTips = {"Header tip 1", "Header tip 2", "Header tip 3"};
        private ExtTableModel    myTableModel;
        private ExtTable         myTable;
        private JScrollPane      myScrollPane;
        private int              lastRow = 0;
        // for example
        private MiniModel mmlRow1 = new MiniModel(1, "cell comment");
        private MiniModel mmlRow2 = new MiniModel(2, "other cell comment");
        // constructor
        public TableHide() {
            this.setTitle("Table column hide test");
            this.setResizable(true);
            this.setLayout(new BorderLayout());
            // build table containing all extended Model's id and name
            myTableModel = new ExtTableModel(null, colNames);
            myTable      = new ExtTable(myTableModel);
            myTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            myTable.setPreferredScrollableViewportSize(new Dimension(500, 130));
            myTable.setFillsViewportHeight(true);
            myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            myTable.getTableHeader().setReorderingAllowed(false);
            myScrollPane = new JScrollPane(myTable);
            this.add(myScrollPane, BorderLayout.CENTER);
            // add some rows, in real application this is more complex
            myTableModel.insertRow(0, new Object[]{ "Basic string", new Boolean(false), mmlRow1 }); lastRow++;
            myTableModel.insertRow(0, new Object[]{ "Other string", new Boolean(true) , mmlRow2 }); lastRow++;
            myTable.setAutoCreateRowSorter(true);
            myTable.getRowSorter().toggleSortOrder(0);
            // this causes the exception
            myTable.removeColumn(myTable.getColumnModel().getColumn(2));
            this.setSize(new Dimension(500,200));
        // inner class to provide an own table model for the extended Models showed on screen. used for booleans
        class ExtTableModel extends DefaultTableModel {
            public ExtTableModel(Object[][] tableData, String[] columnNames) {
                super(tableData, columnNames);
            public boolean isCellEditable(int row, int col) {
                return false;
            public Class getColumnClass(int column){
                Object value=this.getValueAt(0,column);
                return (value==null?Object.class:value.getClass());
        // inner class to privide column header tooltips and cell tooltips
        class ExtTable extends JTable {
            public ExtTable(ExtTableModel extModel) {
                super(extModel);
            // implement table cell tool tip.
            public String getToolTipText(MouseEvent e) {
                String tip             = null;
                Point  p               = e.getPoint();
                int    rowIndex        = rowAtPoint(p);
                int    colIndex        = columnAtPoint(p);
                int    realColumnIndex = convertColumnIndexToModel(colIndex);
                if(rowIndex>=0 && rowIndex<=lastRow) {
                    if(realColumnIndex==0) {
                        MiniModel mml = (MiniModel)getValueAt(rowIndex, 2);
                        tip = mml.getMml_comment();
                    } else {
                        tip = "Some other tooltip function";
                return tip;
            // implement table header tool tip.
            protected JTableHeader createDefaultTableHeader() {
                return new JTableHeader(columnModel) {
                    public String getToolTipText(MouseEvent e) {
                        Point  p         = e.getPoint();
                        int    index     = columnModel.getColumnIndexAtX(p.x);
                        int    realIndex = columnModel.getColumn(index).getModelIndex();
                        return colHeadTips[realIndex];
        // simplified class for usage inside a cell
        public class MiniModel {
            private int        mml_id;
            private String     mml_comment;
            public MiniModel(int mml_id, String mml_comment) {
                this.mml_id      = mml_id;
                this.mml_comment = mml_comment;
            public String getMml_comment() {
                return mml_comment;
            public String toString() {
                return Integer.toString(mml_id); // called when object is displayed
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    new TableHide().setVisible(true);
    }When you show the last column the program works fine. Goal is to have the last column available since it contains extra information about the row, but not to show it.

  • How to forbid Column-Moving in a JTable ?

    Hi,
    anyone knoyw how to forbid the Column-Moving in a JTable ??
    I have a JTable that works fine, but it is still allowed to move the columns. And i want to forbid that.
    This: JTableHeader header = new JTableHeader();
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);
    did not work :-\
    Maybe someone has some ideas and could help me?
    Thx and have a nice day
    Avalon

    >
    Where's your thread, GoldieDork? You do nothing
    besides trolling.no I don't, I ask Java questions but no one answers them apart from the database question where dave and jverd and rage were all nice to me and I was happy that we could all be friends cos they helped me but then they started cussing me again so thats why I no longer talk to those guys.
    I dont know where my thread is now, Sun probably deleted it

Maybe you are looking for

  • Utility to collect/delete unused links?

    [INDD CC]  I inherited a very long do and have to update all links. Is there a way to collect and delete all unused links from the links palette and the links folder once they've been replaced? Kind of like how the swatch palette has a "select all un

  • Cursor styles in OS 10.10

    Installed 10.10 and the cursor now takes different shapes for different functions. Sometimes a double arrow in vertical position sometimes same in horizontal authorities at an angles sometimes a line with U (s) on top and bottom and a line thru middl

  • Upgrade from 1.0 on PC to 1.31 on Mac Problems

    After delaying upgrading LR on my PC, knowing that I was going to a MacBook Pro, I delayed upgrading 1.0. My library of 15,000 images worked fine, albeit slow, due to the older PC. My images are stored on an external drive, while the older .lrdb resi

  • Data Base Reset Alert

    I keep getting the following message on my eMac. It just started about one week ago. "Inconsistencies in your sync information for bookmarks were detected and have been repaired. The next sync for Moble Me and Safari may take longer than usual." What

  • TS2551 Iphoto freezes when going in preferences

    since one day my Iphoto 09 freezes when going in preferences. Can anyone help?