Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:39:42+00:00 2026-05-29T07:39:42+00:00

I have a JTable in my application. I have a custom renderer setup on

  • 0

I have a JTable in my application. I have a custom renderer setup on the table (a JTextArea, with line-wrapping enabled) which allows for multi-line content. The contents of the JTable cells are expected to overflow the bounds of the cell in some cases. I want to do the following:

Instead of making the user drag the row border to resize the cell, I want the user to be able to double-click the row border, so when I detect this, I can automatically resize the height of the cell (height of the row) to show the entire contents of the cell.

My question is, what is the best way to detect a double-click on the row border? I have gotten this to work by setting up a MouseListener on the JTable with a mouseClicked method that looks like this:

public class MouseButtonInputListener extends MouseInputAdapter
{
    private JTable fTable;

    public MouseButtonInputListener(JTable parentTable)
    {
       fTable = parentTable;
    } 

    @Override
    public void mouseClicked(MouseEvent e)
    {

        // Some pre-processing here...

        if(e.getClickCount() == 2 && 
           fTable.getCursor().getType() == Cursor.N_RESIZE_CURSOR)
        {
            // Auto-adjust row height to fit contents...            
        }

    }
}

While this works, i’m not very happy with the line:

fTable.getCursor().getType() == Cursor.N_RESIZE_CURSOR

Any suggestions on a better way to do this? Is the above a reliable approach on all platforms?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:39:42+00:00Added an answer on May 29, 2026 at 7:39 am

    After some searching online, I found the following page:

    http://java.sun.com/products/jlf/ed2/book/HIG.Behavior.html

    amongst other things, it specifies mouse cursor behavior under different circumstances. According to the section on “Pointer Feedback”, the cursor switches between a N_RESIZE_CURSOR and S_RESIZE_CURSOR depending on whether it is the upper or lower boundary of a component that is being hovered over. It’s interesting to note that on 2 out of 3 platforms (Mac and Windows), these cursors are exactly the same. Anyway, it follows that my code should therefore read:

    @Override
    public void mouseClicked(MouseEvent e)
    {
        // Some pre-processing here. Determine row at mouse click location
        int cursorType = fTable.getCursor().getType();
        if(e.getClickCount == 2 && 
          (cursorType == Cursor.N_RESIZE_CURSOR || cursorType == CURSOR.S_RESIZE_CURSOR))
        {
            // Resize row appropriately.
        }
    }
    

    This will work on all platforms. Thanks for the inputs and comments everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Java Swing application which contains components like JTable, JCombobox, JTextArea and
I have a jTable which currently displays and allows editing of a database table,
I have a standalone application in which I have a Jtable. In my table,
I have an application where I have a JTable with line breaks(pressing Enter key
I have a custom cell renderer set in JTable and it works but instead
I want to bind mysql table content with JTable . I have connected sucessfully.
I have a JTable that holds several JPanels using a custom renderer/editor. The JPanel
I have a JTable with a custom cell renderer. The cell is a JPanel
I have a JTable which is loaded from a data-structure using table model.The data-structure
I have a JTable with a custom TableModel called DataTableModel . I initialized the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.