• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic size of JTable

 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic