Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Adding Tooltip to JTable header
Garandi Garandi
Ranch Hand
Posts: 192
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want to set tooltip for table header. I can see the tooltip when the table is loading data, but when loading data is done the tooltip does not show up.
class ColumnHeaderToolTips extends MouseMotionAdapter { // Current column whose tooltip is being displayed. // This variable is used to minimize the calls to setToolTipText(). TableColumn curCol; // Maps TableColumn objects to tooltips Map tips = new HashMap(); // If tooltip is null, removes any tooltip text. public void setToolTip(TableColumn col, String tooltip) { if (tooltip == null) { tips.remove(col); } else { tips.put(col, tooltip); } } public void mouseMoved(MouseEvent evt) { TableColumn col = null; JTableHeader header = (JTableHeader) evt.getSource(); JTable table = header.getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); // Return if not clicked on any column header if (vColIndex >= 0) { col = colModel.getColumn(vColIndex); } if (col != curCol) { header.setToolTipText( (String) tips.get(col)); curCol = col; } } } [B]//This method is called from Constructor[/B] public void setToolTipsForColumnHeader() { ColumnHeaderToolTips tips = new ColumnHeaderToolTips(); JTableHeader header = _tableCDR.getTableHeader(); // Assign a tooltip for each of need columns for (int c = 0; c < _tableCDR.getColumnCount(); c++) { TableColumn col = _tableCDR.getColumnModel().getColumn(c); if (c == 0 || c == 1 || c == 2 || c == 5 || c == 6 || c == 11 || c == 12) { tips.setToolTip(col, "Can be sorted"); } } header.addMouseMotionListener(tips); }
Thank you in advance
Garandi
[ August 14, 2003: Message edited by: Garandi Garandi ]
Garandi Garandi
Ranch Hand
Posts: 192
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The above code works, all I did I set the size of columns first and then set the tooltip and everything looks fine.
Thank you
Garandi
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable column help
Check Box in JTable header
JTable Columns
Adding JComboBox to JTable header
Problem with JTable
More...