Mouse cursor doesnt change to splitter over JTable column header.

Hi, this problem seems to be fixed in 1.6 but does anybody know a work around in 1.5 on Windows XP?
I'm afraid that I haven't been able to locate the relevant bug fix (if any) despite my best efforts with Google and searching these forums.
The problem is that in 1.5 if the parent frame window is invisible then the mouse cursor doesn't change to the column splitter\resize icon when you hover the mouse between two columns on a column headers.
If you run the following code under 1.5.0.7, you don't get the cursor change, if you change f.setVisible(false) to f.setVisible(true) then it works.
public class ColumnResizeTest
    public static void main(String[] args)
        JFrame f = new JFrame("This is a test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 200);
        f.setVisible(false); // change to true to get resize mouse cursor
        test(f);
    public static void test(Frame f)
        JPanel contentPanel = new JPanel(new BorderLayout());
        JDialog d = new JDialog(f);
        d.setSize(200, 400);
        contentPanel.add(new JScrollPane(new JTable(new DefaultTableModel(5, 5))), BorderLayout.CENTER);
        d.setContentPane(contentPanel);
        d.setVisible(true);
}In my application at the point the JTable is displayed, the application frame is always invisible as the JTable is shown from the splash\login screen.
Thanks in advance.
Philip Wilkinson.

Adding a mouse listener to either a cell renderer or cell editor in a table the cell cursor will not work because it is the table which responds to mouse motion events - not the individual cell (at least in the case of MouseEntered and MouseExited).
My solution to this was to add a MouseMotionListener listener to the table and and on the mouseMoved event I called a method which determined whether or not the cursor to display should be a hand cursor or the default cursor.
For example:
* Adds a mouse motion listener to the table.
public void addTableMouseMotionListener()
    table.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent me) {
            displayColumnCursor(me);
* Method to change cursor based on some arbitrary rule.
protected void displayColumnCursor( MouseEvent me ) {
    Point p = me.getPoint();
    int column = columnAtPoint(p);
    int row = rowAtPoint(p);
    String columnName = getColumnName(column);
    if (columnName.equals("SOME_COLUMN")) {
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else {
        setCursor(Cursor.getDefaultCursor());
}Hope this helps solve your problem.
cheers
Greg

Similar Messages

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

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

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

  • Multi-colored JTable column heading?  How?

    Hi,
    I'm looking for a way to have JTable column heading text
    that can be displayed in multiple colors, so one string
    in one column header, might have each letter a different
    color.
    My application requires highlighting some of the letters
    of a word as red, while others are normal text (black).
    I've been using multi-line strings to simulate vertical
    naming for my column header, for example:
    PPP
    I I I
    N N N
    1 2 3
    for PIN1, PIN2, PIN3. The column data has a binary
    one or zero for each pin, grouped together in one JTable
    column. In my application, if there is an error, I want to
    color just the text representing, say PIN2 red and leave
    the surrounding PIN1 and PIN3 black.
    What approach should I take for doing this with JTable?
    Thanks!
    John Roberts
    [email protected]

    You should override the default cell renderer used by Java
    - JTable.getTableHeader().setDefaultRenderer(yourRenderer)
    Extend yourRenderer from JLabel and use HTML tags to change the color.
    - setText on JLabel with the HTML code like "<HTML> <BODY> <FONT COLOR="red"> A </FONT> <FONT COLOR="green"> B </FONT></BODY> </HTML>"

  • How can I change the color of a column header?

    I need to change the color for some column header, how can I do it in webdynpro ABAP? Is it possible?

    hi ,
    i have used in alv....
    <font color="RED">text</font>
    but i think it is not possible to change the colour in table ui element.
    regards,
    sahai.s

  • How to change the height of the column header cells

    Hi,
    I have been working with Oracle BI Discoverer 10g. I want to increase the height of the column header cells. The labels within the column headers are almost cut off. Is there a way to change the height of the column header cells?
    Thanks...

    Hi
    In dic.4.1 ,we are using format heading ,and manipulating by entering extra space and changing font and mode.
    try the same
    Rgds
    NP

  • OS X Cursor doesnt change

    Hi,
    I am currently running 10.5.4 and have encountered a strange problem - whenever i move my mouse cursor over say a hyperlink or resize button, the cursor changes to the relevant symbol and performs the action i.e. resizes the window, but then the cursor sticks in that current shape for a while, until i rapidly move it all over the screen to change it back to the default style.
    Any ideas?
    Thanks.
    Joe

    That does happen to me as well and I don't really have a fix. It mostly happens when I'm reading some text and putting my cursor over the text. Does anybody have an idea.

  • Mouse Cursor doesnt update until mouse is moved.

    I think I'm having the same problem as the person in this post:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=149236
    I'm setting the mouse cursor after certain buttons in a JPanel are pushed, but the cursor image doesn't actually get updated until the mouse is moved. I tried using Toolkit.getDefaultToolkit().sync() and that didn't work. The other solution, which was to fire a mouse event to force it to update, doesn't seem to be ideal.
    Is there any other way to force the cursor image to get updated immediately, without moving the mouse?

    Hmm, I can't reproduce your problem (below is a small test example, that works fine with me) on win9x, neither with jdk1.3, nor with 1.4.
    Greetings
    Jeanette
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    //import de.kleopatra.support.debugon.*;
    /** reported problem: cursor not immediately updated after switching
    *          only after move
    *     1.4, 1.3: not reproducible (win9x)
    *     $Id: TestCursor.java,v 1.1 2002/03/19 11:27:20 Jeanette Exp $
    public class TestCursor {
         protected JFrame frame ;
         protected Cursor current;
         protected JComponent target;
         public TestCursor() {
              frame = new JFrame("TestCursor");
              frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
              frame.getContentPane().add(buildMainPanel());
              frame.getContentPane().add(buildButtonPanel(), BorderLayout.SOUTH);
              frame.pack();          
              frame.setSize(300, 200);
              frame.show();
    //---------------------------helper
         protected void toggleCursor() {
              if (current == null) {
                   current = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
              Cursor temp = target.getCursor();
    //          D.ebug("old cursor: ", temp);
              target.setCursor(current);
              current = temp;
    //---------------------------init ui
         protected JComponent buildMainPanel() {
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(200, 100));
              panel.setBackground(Color.yellow);
              target = panel;
              return panel;
         protected JComponent buildButtonPanel() {
              JPanel panel = new JPanel();
              JButton button = new JButton("do toggle cursor");
              button.setMnemonic('d');
              frame.getRootPane().setDefaultButton(button);
              ActionListener action = new ActionListener() {
                   public void actionPerformed(ActionEvent event) {
                        toggleCursor();
              button.addActionListener(action);
              panel.add(button);
              return panel;
    //---------------------------factory methods
    //---------------------------Main
         public static void main(String[] args) {
         //     LFSwitcher.windowsLF();
              new TestCursor();
    }

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

  • JTable Column Header Problem, Please help me

    What Listener I have to used to get the column index when user change the width of column header using mouse.

    There is no listener that reports this activity. The TableColumnModelListener can only tell you if columns change position or are added/removed from the column model.
    To detect changes, you will need to use a brute force mechanism, namely, to extend the JTableHeader class just a bit.
    When the user clicks on a header to resize a column, there is a property in JTableHeader called ResizingColumn that has a type of TableColumn. It is set by the UI delegate when the drag operation starts to the column being resized. When the drag operation ends, the value of ResizingColumn is set to null. You might start with something like this:
      JTable table = new JTable(...);
      MyTableHeader header = new MyTableHeader();
      table.setHeader(header);
      table.setModel(...);
    class MyTableHeader extends JTableHeader
        public void setResizingColumn(TableColumn column)
            super.setResizingColumn(column);
            if (column != null)
                System.out.println("Resizing Column #" + column.getModelIndex());
            else
                System.out.println("Resizing Ended");
    }This will only work for user resizing of columns, not for sizes changed programmatically or by the automatic sizing features of the header.
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • Arrow on JTables column header

    Hey guys,
    I have a few dialogs with tables on etc, everythings fine, its just one table when the program runs, when u hovver(sp?) over the line on the column header it normally turns into a black arrow like so <--> and the you can resize it.
    But this one table wont do that, ive created these in netbeans and just cant see the difference with the other tables. the columns are still resizable just remains an normal arrow though rather than <-->
    Thanks for any help

    You can't resize the column if use the code below,but the arrow will display
    TableColumn tableColumn = this.getTableHeader().getColumnModel().getColumn(i);
                             tableColumn.setPreferredWidth(columnsize);
                             tableColumn.setMinWidth(columnsize);
                             tableColumn.setMaxWidth(columnsize);reply if it help you..

  • How to have a combobox in JTable column header?

    Any simple ways for doing this? I am trying to get a filter to a JTable, so that only the rows containing the selected value in that column would be shown.
    I first need to get this combobox into the header of a column.

    Thanks.
    I have already tried with this way, but it was too long and complicated to implement into my file.
    Could someone post the principles here.
    Like this:
    // create my combobox
    JComboBox myBox = new JComboBox();
    myBox.addItem("Cat");
    myBox.addItem("Dog");
    // put the combobox to column header
    ??? ANY CODE HERE ???
    Tnx ahead!
    OK!
    AUlo

  • JTable column header to span multiple columns

    Hi people. I've spent the last day trying to do this with no luck. Most of the links in the forum are old and don't exist any more and the ones that lead to some code end up not working on java 5 (I can compile and run but the result is not what I wanted)!
    So my question is this, how do I have a column header that spans more than one column, which has individual column headers below it?
    Thanks, Paul.
    EDIT: I should point out that this is the place I've tried and although the screen shot of the first example looks exactly like what I want to do, it does not work as advertised. [http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples1.html]
    Edited by: Boomah on 05-Nov-2008 15:08

    Something like this?import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.*;
    public class MultiSpanHeader {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new MultiSpanHeader().makeUI();
       public void makeUI() {
          final JTable table = new JTable(5, 6);
          final JTableHeader header = table.getTableHeader();
          header.setReorderingAllowed(false);
          final TableColumnModel model = table.getColumnModel();
          Enumeration<TableColumn> enumColumns = model.getColumns();
          final List<TableColumn> columns = Collections.list(enumColumns);
          final JTable dummy = new JTable(0, 3);
          final JTableHeader dummyHeader = dummy.getTableHeader();
          dummyHeader.setReorderingAllowed(false);
          dummyHeader.setResizingAllowed(false);
          final TableColumnModel dummyModel = dummy.getColumnModel();
          Enumeration<TableColumn> enumDummyColumns = dummyModel.getColumns();
          final List<TableColumn> dummyColumns = Collections.list(enumDummyColumns);
          model.addColumnModelListener(new TableColumnModelListener() {
             @Override
             public void columnAdded(TableColumnModelEvent e) {
             @Override
             public void columnRemoved(TableColumnModelEvent e) {
             @Override
             public void columnMoved(TableColumnModelEvent e) {
             @Override
             public void columnMarginChanged(ChangeEvent e) {
                dummyColumns.get(0).setWidth(columns.get(0).getWidth());
                dummyColumns.get(1).setWidth(columns.get(1).getWidth() +
                      columns.get(2).getWidth());
                dummyColumns.get(2).setWidth(columns.get(3).getWidth() +
                      columns.get(4).getWidth() + columns.get(5).getWidth());
             @Override
             public void columnSelectionChanged(ListSelectionEvent e) {
          JScrollPane pane = new JScrollPane(table);
          pane.setPreferredSize(new Dimension(600, 200));
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(pane);
          frame.pack();
          JPanel panel = new JPanel(new GridLayout(2, 1));
          panel.add(dummyHeader);
          panel.add(header);
          pane.getColumnHeader().setView(panel);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    }Note: this is just presented as an idea, would need a lot of work to make it robust and flexible enough for practical use.
    db

  • Mouse cursor issues (changes back to arrow)

    I keep having this annoying issue with the cursor of my mouse. It works just fine for a while, but after few hours (usually working with PS, Illustrator etc.) there is this thing happening - if I want to resize a window, an Illustrator object, or if I move the cursor over a hyperlink - cursor changes from an arrow to a hand or whatever desired sign - but just for a second and goes back to arrow! It is highly annoying. :/
    Idk the source of this problem, but I might add that I once installed a patch for Yosemite, which changes Helvetica system font for Lucida Grande. I uninstalled it though...
    I use the latest MacBook Pro 13-inch with Yosemite.
    Many thanks.

    Same problem.
    My setup:
    MBP running OS X 10.9
    Apple TV running 6.0 (6646.65)
    Samsung HD TV
    It's only happening when I have mirroring turned on (not extended desktop), and when I have the mirrored resolution set to match the TV. The TV has a larger viewing area than my Macbook Pro. My MBP screen resolution is set to "Scaled: Best for retina"
    This started happening after the update to Mavericks.
    EDIT:
    This solved it for me: I had Air Display running in the background, and the new version of Air Display automatically tries to connect to devices when it's running. My iPad is out, and I think Air Display might have been trying to connect to it. I quit Air Display and the cursor issue is gone.
    Message was edited by: brassknucklenerd

  • 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 column header is not displaying

    Here I have the sample code which is not displaying the header names of each row (Names, Size, Status).
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    public class sample extends JFrame
        JTable table;
        String names[] = {"Names","Size","Status"};
        TableModel model = new AbstractTableModel()
            public Object getValueAt(int row, int col)
                return "Data";
            public int getColumnCount()
                return 3;
            public int getRowCount()
                return 5;
            public String getColumnName(int col)
                return names[col];
        public sample()
            setSize(400,400);
            setDefaultCloseOperation(3);
            Container cp = getContentPane();
            table = new JTable(model);
            cp.add(table);
            setVisible(true);
        public static void main(String a[])
            new sample();
    }Anybody can give idea for me.

    Read the JTable API. It shows you how to do this. In addition it has a link to the tutorial on "How to Use Tables" which contains many examples.

Maybe you are looking for

  • Video playback in Aperture

    Hi, I've imported alot of video in Aperture, converting with handbrake and I can view it fine. My problem is the archaic viewing options that come with Aperture. It's very difficult to make the slider go back or forward. I like to watch my kids sport

  • Totalizing a flow rate but not calculating if a negative number

    I know how to take a flow rate and produce a totalizer using an integration. What I would like to do is not calculate the integration if the incoming rate should be a negative value. Thanks in advance for your help.

  • Stdout from ejb not working

    I have an EAR with 2 ejbs that works fine in the Sun SDK app server, but when I deploy it in Application Server 7 none of my trace messages get printed to the app server console. The strange thing is that if I restart the server, then my ejb trace me

  • Material No and Charecter length

    Dear All, Can we increase the charecter lengh of material? I mean in SAP std. material No length is 18 and description length is 40 can we increase it? If, yes then how to do it?

  • Set 9002 infotype field required

    Hi! We have a customized infotype : 9002. There are two fields that we need to set them to required. How to do that? Is it custuminzing or abap? Thanks in advance