Emergency - resize JTable's row height

Hi,there!
Could I modify the row height by mouse drag just like modify column width?
Some codes are better.
Thanks a lot!

Check out the link shown below and vote for it... may be sun will fix it a little faster:
http://developer.java.sun.com/developer/bugParade/bugs/4714237.html
;o)
V.V.

Similar Messages

  • Resizing a JList with variable row heights, not updating the "picture"

    Firstly I would like to apologize for posting this Swing question here, but I was unable to find the Swing category, if someone could direct me to that I would be most grateful.
    Ok, so in abstract what I am trying to do is have a JList with resizable rows to act as a row header for a JTable (exactly like the row headers in OO Calc or MS Excel).
    What I have is a RowHeaderRenderer:
    public class RowHeaderRenderer extends JLabel implements ListCellRendererand it has a private member:
    private Vector<Integer>        _rowHeights            = new Vector<Integer>();which contains a list of all the variable row heights.
    Then there is my getListCellRendererComponent method:
        public Component getListCellRendererComponent(    JList         list,
                                                          Object        value,
                                                          int           index,
                                                          boolean       isSelected,
                                                          boolean       cellHasFocus)
            // Make sure the value is not null
            if(value == null)
                this.setText("");
            else
                this.setText(value.toString());
            // This is where height of the row is actually changed
            // This method is fed values from the _rowHeights vector
            this.setPreferredSize(new Dimension(this.getPreferredSize().width, _rowHeights.elementAt(index)));
            return this;
        }And then I have a row header:
    public class RowHeader extends JList implements TableModelListener, MouseListener, MouseMotionListenerand you may be interested in its constructor:
        public RowHeader(JTable table)
            _table = table;
            _rowHeaderRenderer = new RowHeaderRenderer(_table);
            this.setFixedCellWidth                        (50);
            this.setCellRenderer                        (_rowHeaderRenderer);
            // TODO: grab this value from the parent view table
            JScrollPane panel = new JScrollPane();
            this.setBackground(panel.getBackground());
            this.addMouseMotionListener                    (this);
            this.addMouseListener                        (this);
            this.setModel                                (new DefaultListModel());
            table.getModel().addTableModelListener        (this);
            this.tableChanged                            (new TableModelEvent(_table.getModel()));
        }and as you can see from my mouse dragged event:
        public void mouseDragged(MouseEvent e)
            if(_resizing == true)
                int resizingRowHeight = _rowHeaderRenderer.getRowHeight(_resizingRow);
                _rowHeaderRenderer.setRowHeight(_resizingRow, resizingRowHeight + (e.getPoint().y - _cursorPreviousY));
                _cursorPreviousY = e.getPoint().y;  
        }all I am doing is passing the rowHeaderRenderer the values the currently resizing row should be, which works fine. The values are being changed and are accurate.
    The issue I am having is that while this dragging is going on the row does not appear to be resizing. In other words the "picture" of the row remains unchanged even though I change the values in the renderer. I tried calling:
    this.validate();and
    this.repaint();at the end of that mousedDragged method, but to no avail, neither of them worked.
    Again, I verified that I am passing the correct data in the RowHeaderRenderer.
    So, anyone have any ideas how I should get the image of the RowHeader (JList) to update after calling my MouseDragged event?
    Thank you for your time,
    Brandon

    I was able to fix this some time ago. Here is the solution:
         public void mouseDragged(MouseEvent e)
              if(_resizing == true)
                   int newHeight = _previousHeight + (e.getPoint().y - _cursorPreviousY);
                   if(newHeight < _minRowHeight)
                        newHeight = _minRowHeight;
                   _rowHeaderRenderer.setRowHeight(_resizingRow, newHeight);
                   _table.setRowHeight(_resizingRow, newHeight);
              this.updateUI();
         }

  • JTable and Adjusrt Row Height

    Hi,
    1. Can we adjust variable row height for each row,
    2. Also as we adjust the column widht, can we adjust the row height by dragging,
    3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar,
    Ashish

    That's a lot of questions..... but here are your answers:
    1. Can we adjust variable row height for each row,Yes, use JTable's setRowHeight method to set the height of each row.
    2. Also as we adjust the column widht, can we adjust the row height by dragging,You should be able to adjust the column width by clicking the mouse on the edge of the column header and drag. There is no automatic provision for changing the row height that way -- you'll have to add a mouse listener to the rowheader and write your own code to perform the resizing.
    3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar, You'll have to figure out how many rows (based on the sum of the individual row's height) the textarea occupies (taking into consideration the font that you used to render the textarea). I have my own way of doing things but if you search this forum, you'll find a lot of discussion on how to do it.
    ;o)
    V.V.

  • JTable and adjusting Row height

    Hi,
    How to make a row height adjustable, like user can click on the row and drap to increase the height of the row,
    Also if i have JTextArea as cell rendere how do i dynamically adjust the row height to display all the text
    Ashish

    That's a lot of questions..... but here are your answers:
    1. Can we adjust variable row height for each row,Yes, use JTable's setRowHeight method to set the height of each row.
    2. Also as we adjust the column widht, can we adjust the row height by dragging,You should be able to adjust the column width by clicking the mouse on the edge of the column header and drag. There is no automatic provision for changing the row height that way -- you'll have to add a mouse listener to the rowheader and write your own code to perform the resizing.
    3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar, You'll have to figure out how many rows (based on the sum of the individual row's height) the textarea occupies (taking into consideration the font that you used to render the textarea). I have my own way of doing things but if you search this forum, you'll find a lot of discussion on how to do it.
    ;o)
    V.V.

  • How to bind JTable row height to the maximum height of a the columns

    Suppose i have a JTable. data setup is done. Thing is whenever data font size increases table row height should change. How?

    Add a PropertyChangeListener to the table to listen for a font change event. Then use the setRowHeight() method of the table.

  • How can I resize table row height?

    I found that there are some method which can set the resize model for table column. Is there any of them to set the row height resize? Because some cell value in my table will across two lines.

    method but no auto resizeWell, thats not what your original question asked. I'm not a mind reader.
    Your out of luck, you need to calculate the size yourself.

  • Dinamic JTable Rows Height

    Hi!
    Is it possible to change dinamically and automatically JTable row height depending on a cell content to display it correctlly wraping the text?
    In some of my cells content is too long and It's difficult to display it properly ...
    Thanks!

    This link might help:
    http://www.javaspecialists.co.za/archive/GUI.html

  • Row Height Resizing

    Has anybody figured out how to make the row height smaller than the 0.11 that is allowed?
    I am trying to make to row smaller, to change the design, mainly I do not want the cell outline to touch the header row, but I do not want it as far away as 0.11

    Has anybody figured out how to make the row height smaller than the 0.11 that is allowed?
    I am trying to make to row smaller, to change the design, mainly I do not want the cell outline to touch the header row, but I do not want it as far away as 0.11

  • Dynamically resize JTable cell to fit a JList

    Hi!
    I've been banging my head trying to add some dynamic behavior to a TableCellEditor. In short I'm trying trying to make it resize the height of the current row (the one it is in) to reflect the changes made to the JList used to let the user edit the cells value (which is a list of items).
    I've come across some threads dealing with the problem of resizing a cell to fit its content. This however is usually only done once (in the 'getTableCellEditorComponent' function) and so only provides half the answer. Also, since the editor is only active during cell editing I've been trying to make it revert to the old cell height after the editing is done.
    So far I have not come up with any decent solution to this problem and was hoping someone out there might have an idea or have read something similar and can point me to something helpful... anyone?
    Cheers!
    Teo

    The Swing tutorial on[url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables shows how to dynamically change the size to Table Columns.
    If you need help calculating the acutal size then try searching the forum. Using keywords "resize jtable column" (keywords I took directly from your topic title) I found some promising postings.

  • Change row height of a table by dragging

    Hi,
    One of my swing projects has a requirement that the user should be able to resize the height of individual rows of a table by dragging the row separator with the mouse.
    JTable by default allows us to drag the column separators and change the column width. But the row heights are not adjustable in a similar way.
    Is it possible to do so? I guess I will have to write a listener for the rows, don't know how to go about it though.
    Any help in this regard would be highly appreciated.
    Thanks.

    Hi,
    Well here is the table you're talkking about. I tried adding the cellrender and listen to the drag event. Could not proceed much though. I am still trying. In the mean time if any of you can progress on this then please let me know.
    I've attached my full code listing here.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.Cursor;
    public class LineNumberTable extends JTable
         private JTable mainTable;
         public LineNumberTable(JTable table){
              super();
              mainTable = table;
              setAutoCreateColumnsFromModel(false);
              setModel(mainTable.getModel());
              setSelectionModel(mainTable.getSelectionModel());
              setAutoscrolls( false );
              addColumn(new TableColumn());
              getColumnModel().getColumn(0).setCellRenderer( mainTable.getTableHeader().getDefaultRenderer());
              //Attaching my cell renderer
              getColumnModel().getColumn(0).setCellRenderer(new myCellRenderer());
              getColumnModel().getColumn(0).setPreferredWidth(10);
              setPreferredScrollableViewportSize(getPreferredSize());
         public boolean isCellEditable(int row, int column) {
              return false;
         public Object getValueAt(int row, int column) {
              return new Integer(row + 1);
         public int getRowHeight(int row) {
              return mainTable.getRowHeight();
         public static void main(String[] args) throws Exception {
              DefaultTableModel model = new DefaultTableModel(100, 5);
              JTable table = new JTable(model);
              JScrollPane scrollPane = new JScrollPane( table );
              JTable lineTable = new LineNumberTable( table );
              scrollPane.setRowHeaderView( lineTable );
              JFrame frame = new JFrame( "Line Number Table" );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
              frame.setSize(400, 300);
              frame.setVisible(true);
         class myCellRenderer extends DefaultTableCellRenderer implements MouseListener, MouseMotionListener {
              private Point start;
              private Point end;
              public void mouseClicked(MouseEvent e) {
              public void mouseDragged(MouseEvent e) {
              public void mouseEntered(MouseEvent e) {
                   setCursor(new Cursor(java.awt.Frame.N_RESIZE_CURSOR));
              public void mouseExited(MouseEvent e) {
                   setCursor(new Cursor(java.awt.Frame.N_RESIZE_CURSOR));
              public void mouseMoved(MouseEvent e) {
              public void mousePressed(MouseEvent e) {
                   start = e.getPoint();
               public void mouseReleased(MouseEvent e) {
                    end = e.getPoint();
                    int inc = end.y - start.y;
                    LineNumberTable.this.setRowHeight(inc + LineNumberTable.this.getRowHeight());
    }

  • JTable Blank Rows When INSERT/DELETE in other panel with same ViewObject

    Hi,
    Jdev 10.1.2
    JClient
    2 panels based on same ViewObject in same AM
    One panel with Grid UI => JTable
    Other panel with Form UI
    When I insert or delete a record in the panel with Form UI and return to the panel with JTable blank rows are displayed.
    The problem remains even after commiting before returning to JTable panel.
    When I activate the execute button in the JTable panel, the display is OK but the currency is lost.
    I suppose calling the refresh method when returning to the JTable panel should solve the problem.
    Can you please suggest me a server-side/model workaround:
    refresh (which option to use ??)
    Thanks
    Frederic
    PS I tried the workaround of thread 10.1.2 JClient binding Error. but that doesn't help.

    Same problem with default wizard generated Master-Detail Form.
    When in the detail more then 10 rows exist, the scrollbar shows that not all rows are displayed.
    If I use the scrollbar to view the last rows they are blank, in order to display them I must activate the next button one time for each additional row.
    The workaround is to enter -1 in the range size of the iterator.
    But what if the range size is 10.
    Is the blank rows display a bug?
    OR
    Must the scrolling area (size of JScrollPane) be defined according to the range size of the iterator?
    If the latter is true:
    Can somebody give me some clues on which attributes of the JScrollPane must be set (PreferredSize, MinimumSize ??) and on how to calculate this area: total width & total height if the row height for the table is set to 20?
    Your help will be appreciated
    Frederic

  • How to set  row height  for  each row

    Hi
    i am trying to set rowheight of row in a JTable using setRowHeight(row,rowheight)
    it is not affecting on Table.but if i use setRowheight(rowheight) it applying
    entire table ,please help me to solve this problem
    after setRowHeight(row,rowheight), i am calling firechanged() method also ,i t will not affecting please hemp me
    how to set row height at runtime in a JTable

    Ok fine... do one thing... post ur code here let me check and tell u....
    Ciya.....

  • Row height

    hi,
    I'm new with java. I have a JTable with small rows
    I used the setRowHeigth method to change the heigth for my rows, but I don't know how to change the height of the header row
    need help

    Actually I used the row height to be able to space elements and to allow for the creation of double lines. I needed to be able to design the form as well as mathematically calculate the information entered on the form... hence the spreadsheet approach to it. AW didn't do double lines but you could do them if you created very narrow rows/columns. The narrow rows/columns also allowed you to precisely space entry fields so that you could replicate existing forms. I'll have to send feedback.

  • Row height in tableheader

    hi
    how can i change row height in tableheader of JTable? i cant find any method to change it. any idea?
    thx
    rsobies

    One way -
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.util.regex.*;
    public class MultiLineTableCell extends JFrame
        private Object[][] data =
            {"This\nis\na\ncell\nwith\nsome\nlines.", "This\nis\na\ncell\nwith\nmany\nmany\nmany\nlines","Two\nLines"},
            {"A\nQuad\nRow\nline.","2\n\n\n\n\n\n\n\n\n\n\nLines",null},
            {"Just two\nlines","Just\n3\nlines","A single longer line."},
        private Object[] headers =
            "<html><body align=center>Column<br>1","<html><body align=center>Column<br>2","<html><body align=center>Column<br>3",
        MultiLineTableCell()
            super( "Multi-Line Cell Example" );
            setDefaultCloseOperation( EXIT_ON_CLOSE );
            DefaultTableModel dm = new DefaultTableModel()
                public Class getColumnClass(int columnIndex)
                    return Integer.class;
            dm.setDataVector(data, headers);
            JTable table = new JTable( dm );
            table.setDefaultRenderer(Integer.class, new MultiLineCellRenderer());
            JScrollPane scroll = new JScrollPane( table );
            getContentPane().add( scroll );
            setSize( 400, 130 );
        public static void main(String[] args)
            new MultiLineTableCell().setVisible(true);
        static public class MultiLineCellRenderer extends JList implements TableCellRenderer
            protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
            protected Pattern lineSplitterPattern = Pattern.compile("\n+");
            // We need a place to store the color the JLabel should be returned
            // to after its foreground and background colors have been set
            // to the selection background color.
            // These ivars will be made protected when their names are finalized.
            private Color unselectedForeground;
            private Color unselectedBackground;
            public MultiLineCellRenderer()
                super();
                setOpaque(true);
                setBorder(noFocusBorder);
                ListCellRenderer renderer = getCellRenderer();
                ((JLabel)renderer).setHorizontalAlignment(JLabel.CENTER);
             * Overrides <code>JComponent.setForeground</code> to assign
             * the unselected-foreground color to the specified color.
             * @param c set the foreground color to this value
            public void setForeground(Color c)
                super.setForeground(c);
                unselectedForeground = c;
             * Overrides <code>JComponent.setBackground</code> to assign
             * the unselected-background color to the specified color.
             * @param c set the background color to this value
            public void setBackground(Color c)
                super.setBackground(c);
                unselectedBackground = c;
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column)
                if (isSelected)
                    super.setForeground(table.getSelectionForeground());
                    super.setBackground(table.getSelectionBackground());
                else
                    super.setForeground((unselectedForeground != null) ? unselectedForeground
                            : table.getForeground());
                    super.setBackground((unselectedBackground != null) ? unselectedBackground
                            : table.getBackground());
                setFont(table.getFont());
                if (hasFocus)
                    Border border = null;
                    if (isSelected)
                        border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
                    if (border == null)
                        border = UIManager.getBorder("Table.focusCellHighlightBorder");
                    setBorder(border);
                    if (!isSelected && table.isCellEditable(row, column))
                        Color col = UIManager.getColor("Table.focusCellForeground");
                        if (col != null)
                            super.setForeground(col);
                        col = UIManager.getColor("Table.focusCellBackground");
                        if (col != null)
                            super.setBackground(col);
                else
                    setBorder(noFocusBorder);
                String str = (value == null) ? "" : value instanceof String ? (String)value : value.toString();
                String[] lines = lineSplitterPattern.split(str);
                setListData(lines);
                table.setRowHeight(row, Math.max(getPreferredSize().height, table.getRowHeight(row)));
                return this;
    }

  • Changing row height

    Hi,
    In an AdvancedDataGrid, is it possibe for the user to increase or decrease the row height by dragging/pulling the separations/dividers between the rows with mouse? This is similar to what we can do in an Excel sheet.
    If it is possible, can anyone let me know how this can be done.
    Thanks

    [url http://java.sun.com/docs/books/tutorial/uiswing/events/componentlistener.html]How to Write a Component Listener
    Add the listener to the frame and then reset the row height when the frame is resized.

Maybe you are looking for

  • Multiple e-mail addresses consolidation

    I did something stupid and registered with iTunes under two e-mail addresses. I'm trying to consolidate them, but because they are registered under different passwords iTunes tells me my e-mail address is unavailable. How can I consolidate these thin

  • PO Text to be printed in GR-Slip.

    Hi There is a requirement wherein i have to print the Texts(For ex Quality instructions....) that are communicated to my vendor in the time of Goods receipt at my GR slip. Is there any way to print such texts which i feed in PO creation at the time o

  • Skinning in ADF 11g

    Hi all, I have created a CSS file:*myCompanySkin.css* af|inputText::label {font-weight: bold} and then i have created a file Trinidad-skins.xml <?xml version="1.0" encoding="windows-1252" ?> <skins xmlns="http://myfaces.apache.org/trinidad/skin"> <sk

  • Setting Background Colour with a Value Retrieved from a Database

    I'm retrieving different colours from a database and I want to set the background colour of a canvas to the colour retrieved. I've tried doing the following: <mx:TileList x="2" y="237" direction="horizontal" dataProvider="{MakeUpColours.lastResult.Co

  • Can automation plug-in gets error notification from Photoshop ?

    Hi All, Suppose I open the photoshop file(.psd) and font is missing in the layer. Photoshop shows error dialog box. Can automation plug-in get any kind of notification regarding this font missing in layer ? I want to do some stuff if font is missing