hello_kets
asked on
How to show resize indicator when user want to resize Jtable header.
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
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
ASKER
Please can you send the code for this.
thanx in advance.
ketan
thanx in advance.
ketan
ASKER
I used
************************** ***
JTableHeader header = table.getTableHeader();
header.setResizingAllowed( true);
for(int i = 0; i < table.getColumnCount() ; i++)
{
header.setResizingColumn(t able.getCo lumnModel( ).getColum n(i));
}
************************** ****
but still it is not working.
Ketan
**************************
JTableHeader header = table.getTableHeader();
header.setResizingAllowed(
for(int i = 0; i < table.getColumnCount() ; i++)
{
header.setResizingColumn(t
}
**************************
but still it is not working.
Ketan
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?
I tested some sample code for a JTable.... even if you set table.setEnabled ( false ), the columns are still resizable.
Have you used table.setAutoResizeMode () anywhere?
Try: table.setAutoResizeMode ( JTable.AUTO_RESIZE_ALL_COL UMNS ) ;
(I hope you are not doing table.setAutoResizeMode ( JTable.AUTO_RESIZE_OFF ) ; anywhere).
(I hope you are not doing table.setAutoResizeMode ( JTable.AUTO_RESIZE_OFF ) ; anywhere).
See the JTable examples from the Java developer's almanac:
http://www.javaalmanac.com/cgi-bin/search/find.pl?words=JTable
http://www.javaalmanac.com/cgi-bin/search/find.pl?words=JTable
ASKER
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(JT able.AUTO_ RESIZE_ALL _COLUMNS);
table.setAutoCreateColumns FromModel( false);
table.getTableHeader().set Reordering Allowed(fa lse);
JTableHeader header = table.getTableHeader();
header.setResizingAllowed( true);
for(int i = 0; i < table.getColumnCount() ; i++)
{
header.setResizingColumn(t able.getCo lumnModel( ).getColum n(i));
}
************************** ******
Ketan
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(JT
table.setAutoCreateColumns
table.getTableHeader().set
JTableHeader header = table.getTableHeader();
header.setResizingAllowed(
for(int i = 0; i < table.getColumnCount() ; i++)
{
header.setResizingColumn(t
}
**************************
Ketan
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
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"
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_
// 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
ASKER
yes your code is working fine...
I have removed all the setting of the jtable but even then it is not showing the '<-->'.
I have removed all the setting of the jtable but even then it is not showing the '<-->'.
Post your code.
ASKER
Hi sorry...
i Got the answer. Actually i was setting
JScrollPane scrollPane = new JScrollPane ( jtesttable ) ;
jTablePanel.add ( scrollPane ) ;
jTablePanel.setEnabled(fal se); /// Here was the problem.
when i removed the line 'jTablePanel.setEnabled(fa lse);' its astred working.
thanx for the help.
Regards
Ketan
i Got the answer. Actually i was setting
JScrollPane scrollPane = new JScrollPane ( jtesttable ) ;
jTablePanel.add ( scrollPane ) ;
jTablePanel.setEnabled(fal
when i removed the line 'jTablePanel.setEnabled(fa
thanx for the help.
Regards
Ketan
That is why I posted that code ;-) so that you can see where you went wrong.
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.
Because setting your table's containing Panel to disabled would automatically mean that all things inside the panel (including the JTable) would be disabled.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks, AI.
setResizingColumn(TableCol
This way, java by default takes care of showing that cursor.
Regards,
Muruga