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 7853245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:37:34+00:00 2026-06-02T19:37:34+00:00

Please tell me, how to make a JTable column to contain JTextAreas, so the

  • 0

Please tell me, how to make a JTable column to contain JTextAreas,
so the cell’s height will increase when user types a lot of text and
we can see more than one line (cell gets expanded; as result, row will expand too)

  • 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-06-02T19:37:36+00:00Added an answer on June 2, 2026 at 7:37 pm

    You need to write your own cell renderer and editor based on JTextArea:

        public class Start
    {
        public static class JTextPaneCellEditor extends AbstractCellEditor implements TableCellEditor, KeyListener
        {
            private JViewport viewport;
            private JTable table;
            private int row;
            private JTextPane pane;
    
            public JTextPaneCellEditor(){
                viewport = new JViewport();
                pane = new JTextPane();
                viewport.add(pane);
                pane.addKeyListener(this);
            }
    
            @Override public Object getCellEditorValue(){
                return pane.getText();
            }
    
            @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column){
                this.table = table;
                this.row = row;
                pane.setText(value.toString());
                int newHeight = (int)pane.getPreferredSize().getHeight();
                if(table.getRowHeight(row) < newHeight){
                    table.setRowHeight(row, newHeight);
                }
                return pane;
            }
    
            @Override public boolean isCellEditable(EventObject e){
                if (e instanceof MouseEvent) {
                    return ((MouseEvent)e).getClickCount() >= 2;
                }
                return true;
            }
    
            @Override public void keyTyped(KeyEvent e){
                table.setRowHeight(row, (int)pane.getPreferredSize().getHeight());
            }
    
            @Override public void keyPressed(KeyEvent e){
                if(e.getKeyCode() == KeyEvent.VK_ENTER){
                    stopCellEditing();
                }
            }
    
            @Override public void keyReleased(KeyEvent e){
            }
        }
    
        private static class JTextPaneCellRenderer extends JViewport implements TableCellRenderer
        {
            JTextPane pane;
            JTextPaneCellRenderer(){
                pane = new JTextPane();
                add(pane);
            }
    
            @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
                pane.setText(value.toString());
                table.setRowHeight(row, (int)pane.getPreferredSize().getHeight());
                return this;
            }
        }
    
        public static void main(String[] args){
            JTable table = new JTable(new String[][]{{"String String String String StringString String String String StringString String String String StringString String String String StringString String String String String"}, {"String 2"}}, new String[]{"Column"});
            table.setDefaultRenderer(Object.class, new JTextPaneCellRenderer());
            table.setDefaultEditor(Object.class, new JTextPaneCellEditor());
    
            JFrame test = new JFrame();
            test.add(new JScrollPane(table));
            test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            test.setSize(300, 300);
            test.setLocationRelativeTo(null);
            test.setVisible(true);
        }
    }
    

    EDIT: add viewports for better sizing. But the row is still not expanded on first edit. Does anyone have any ideas?

    EDIT2: I agree with the comments. The thing you want is possible, but you need untested, hackish custom implementation. You will be better off if you redesigned your layout to exclude such JTable sorcery.

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

Sidebar

Related Questions

Could someone please tell me how to make an image appear when the user
Could you please tell me how to make a fonction on Android which will
Please tell me a way on how to make that if the user has
Can anyone please tell me how do I make this script run in IE
I want to make a drop-down list from scratch. Can anyone please tell me
Please tell me will BlackBerry application till OS 7.1 work for new BlackBerry OS
Please tell me what will the call to given function return and how? The
please tell me how to make secure SWF files, so that decompilers like sothink
Can you please tell me how can I make a simple connection with remote
Hi please tell me how to make this screen in blackberry. my data is

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.