aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Dynamic size of JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamic size of JTable" Watch "Dynamic size of JTable" New topic
Author

Dynamic size of JTable

dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103
Hi,

I want to insert a JTable on to JTextArea. In this case I am not going to insert a JScrollPane. So I need to create a JTable that have dynamic size. How can I do this? please help me to do this.

Thank you.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
do you really want to add a JTable to a JTextArea?
or just add the table's data to the textArea?

you can make your table look a bit like a textArea, if for displaying only, by
table.setGridColor(table.getBackground());
dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103
Michael Dunn wrote:do you really want to add a JTable to a JTextArea?
or just add the table's data to the textArea?




Hi,

Actually I want to add table data into textArea. but the problem is how can I set text as column wise and row wise? because some data have small length and some ones have large length. Please help me.


you can make your table look a bit like a textArea, if for displaying only, by
table.setGridColor(table.getBackground());


Using thi grid color, we can only change the color. In this case also we need to insert a scrollpane. but still the size of jtable is static.

Thank you.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you can show the table's data in a textArea, but you'd need to:
set the font to monospaced (or get into the area of fontMetrics, which adds complexity)
add a fixed length 'pad' of say 20 spaces, which you'd manipulate along with the length of the string to be displayed

from what you've described, it still seems easier to match the gridColor to the background, so it's 'invisible',
then set the table header to null. this will give you a scrollable area, no header
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Michael Dunn wrote:.. it still seems easier to match the gridColor to the background, so it's 'invisible',


Easier still to use JTable#setShowGrid(false);
dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103
Hi,

Now it is ok . I did insert tables into textarea. Now I want to print this textarea. To print this I used " txtarea.print(); ". Now the Problem is, textarea was print without Jtable. Actually I have 3 table to print. that because I use a textarea. I did insert that 3 tables into textarea and try to print. but it is not work properly. because the tables are not in the printed sheet.In this case only print the text on the textarea. Now what I want to do? Please help.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic size of JTable