Solved

How to show resize indicator when user want to resize Jtable header.

Posted on 2004-03-21
19
859 Views
Last Modified: 2008-01-16
Hi,
  I am using the swing to draw Jtable. But i am not able to get the resize poniter indicator when user put the mouse between edges of the two column header. I want to show a pointer so that user can understand that he can resize the column size.

regards

Ketan
0
Comment
Question by:hello_kets
  • 11
  • 5
19 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10646902
Pass your TableColumn to the JTableHeader,

setResizingColumn(TableColumn aColumn)  all the columns that you need to resize.

This way, java by default takes care of showing that cursor.


Regards,
Muruga
0
 

Author Comment

by:hello_kets
ID: 10646926
Please can you send the code for this.
thanx in advance.

ketan
0
 

Author Comment

by:hello_kets
ID: 10647033
I used
*****************************
JTableHeader header = table.getTableHeader();
header.setResizingAllowed(true);

for(int i = 0; i < table.getColumnCount() ; i++)
{
     header.setResizingColumn(table.getColumnModel().getColumn(i));
}

******************************
but still it is not working.

Ketan
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647054
As far as I know, you don't need to set it at all, because it is resizable by default. I guess you must be setting it to non-resizable or something. Have you set your JTable to enabled ( false ) or something like that? Can you post your updated code?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647061
I tested some sample code for a JTable.... even if you set table.setEnabled ( false ), the columns are still resizable.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647074
Have you used table.setAutoResizeMode () anywhere?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647080
Try: table.setAutoResizeMode ( JTable.AUTO_RESIZE_ALL_COLUMNS ) ;

(I hope you are not doing table.setAutoResizeMode ( JTable.AUTO_RESIZE_OFF ) ; anywhere).
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647086
See the JTable examples from the Java developer's almanac:

http://www.javaalmanac.com/cgi-bin/search/find.pl?words=JTable
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hello_kets
ID: 10647180
Hi all,
  I think our subject is diverting. I am able to resize the columns but i want so show '<-->' between header edge. I have set the parameters like.

********
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setAutoCreateColumnsFromModel(false);
table.getTableHeader().setReorderingAllowed(false);
JTableHeader header = table.getTableHeader();
header.setResizingAllowed(true);
for(int i = 0; i < table.getColumnCount() ; i++)
{
     header.setResizingColumn(table.getColumnModel().getColumn(i));
}
********************************

Ketan

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647385
I guess that if the columns are resizable then the user will be able to see the '<-->' between the header-edges of the columns. Try this sample code and tell me if it shows it to you the way you want:

import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;

class JTableTest extends JPanel
{
      JTableTest () // constructor ()
      {
            JPanel jTablePanel = new JPanel ( new BorderLayout () ) ;
            String columnNames[] = {"Title","Author","Issued","Shelf No."};
            Object objArray[][] = new Object[1][4] ;

            objArray[0][0] = "A" ;
            objArray[0][1] = "B" ;
            objArray[0][2] = "C" ;
            objArray[0][3] = "D" ;

            final JTable jTabBook = new JTable ( objArray, columnNames ) ;
            jTabBook.setEnabled ( false ) ;
            jTabBook.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION ) ;
            // jTabBook.setEnabled ( false ) ;
            JScrollPane scrollPane = new JScrollPane ( jTabBook ) ;
            jTablePanel.add ( scrollPane ) ;
            jTablePanel.setBackground ( Color.white ) ;
            add ( jTablePanel ) ;
            // show () ;

      } // end of constructor ()

      public static void main(String[] args)
      {
            JFrame jfMyFrame = new JFrame () ;
            jfMyFrame.getContentPane ().add ( new JTableTest () ) ;
            jfMyFrame.setSize ( 800, 600 ) ;
            jfMyFrame.show () ;

      } // end of main ()

} // class definition over
0
 

Author Comment

by:hello_kets
ID: 10647645
yes your code is working fine...
I have removed all the setting of the jtable but even then it is not showing the '<-->'.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647676
Post your code.
0
 

Author Comment

by:hello_kets
ID: 10647811
Hi sorry...
i Got the answer. Actually i was setting

JScrollPane scrollPane = new JScrollPane ( jtesttable ) ;
jTablePanel.add ( scrollPane ) ;
jTablePanel.setEnabled(false);   /// Here was the problem.

when i removed the line 'jTablePanel.setEnabled(false);' its astred working.

thanx for the help.

Regards

Ketan
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647831
That is why I posted that code ;-) so that you can see where you went wrong.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10647840
That is also why I asked: >> Have you set your JTable to enabled ( false ) or something like that?

Because setting your table's containing Panel to disabled would automatically mean that all things inside the panel (including the JTable) would be disabled.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 125 total points
ID: 10656020
As a matter of fact, the reason why the resizing would be disabled will be because the table itself is disabled (because the panel is disabled). That is exactly what I aimed at when I said:

>> Have you set your JTable to enabled ( false ) or something like that?

And I also hope that my posting the other sample code helped the questioner in finding his mistake. Can I claim some points for this now?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10694469
Thanks, AI.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 38
firstswap challenge 20 65
JDeveloper 12c for 32 bit 4 67
JList custom Cell Renderer refresh 15 53
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now