Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) How do I create a table? (Read 12894 times)
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
How do I create a table?
May 2nd, 2007 at 2:11pm
Print Post  
I am trying to create a Table object.
For now, all my code has is:

FlowChart chart = new FlowChart();
chart.addFlowChartListener (new MyFlowChartAdapter());
Table table = chart.createTable(10,10,100,100);

Somehow the new Table causes NullPointerException everytime it runs. Does anyone have any idea why it's failing like that?
Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #1 - May 2nd, 2007 at 3:03pm
Print Post  
I think this happens when the flowchart is not yet added to a container frame. If you first add the flowchart to a container, CreateTable should work fine. If I remember correctly, the exception is thrown somewhere in a Swing FontManager object when the table tries to get some font metrics. Apparently the FontManager does not work when the component is not added to the Swing hierarchy. However we found this after the 1.1 release and haven't fixed it yet.

Stoyan
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #2 - May 3rd, 2007 at 7:58am
Print Post  
Now it does work fine. Thanks!
A new problem occurs: when I try to write text inside the table cells - the text isn't seen.
I used the code you've attached to your demo (on "Class-hierarchy diagram"), but I see no text on screen. The table caption is een clearly, though.

the code is:

Table table = chart.createTable(10,10,200,200);
table.redimTable(1, 20);
table.setTextColor(Color.BLACK);
for (int i = 0; i < table.getRowCount(); i++)
                  table.getCell(0, i).setText("Row" + new Integer(i).toString());
table.setCaptionHeight(20);
table.setCaption("Test1");

thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #3 - May 3rd, 2007 at 8:33am
Print Post  
Maybe the first and only column is not wide enough. Even if it does not display cell borders on the right side, the column has fixed width of 18 points by default. Try resizing the column to 200 too, or set its ColumnSyle to AutoWidth.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #4 - May 3rd, 2007 at 9:14am
Print Post  
I've added those two lines:

table.getColumns().get(0).setColumnStyle(ColumnStyle.AutoWidth);
table.getColumns().get(0).setWidth(200);

just before the "for" loop - but still the same. The table appears textless.
Do you have an example class of Table usage that I can run and test to see what is the difference?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #5 - May 3rd, 2007 at 9:20am
Print Post  
Maybe the rows should be larger too. What happens if you resize the first row? e.g.

table.getRows().get(0).setHeight(50);

Or could you call saveToFile() and email me the diagram, so we can try this here?

Stoyan
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #6 - May 3rd, 2007 at 9:36am
Print Post  
I've tried to change the row height - and it worked!
I searched for a way to determine to row height automatically - but couldn't. Is there a way at leat to calculate from a text what will be the row height needed for it?

Thanks again!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #7 - May 3rd, 2007 at 9:44am
Print Post  
There is a Table.ResizeToFitText() method in Flowchart.NET. We will port it to Java for the next JDiagram version, which we plan to release next week.

Until then you could use a FontMetrics object to measure the text height. You will need to set the font in a Graphics object, then call Graphics.getFontMetrics(), and finally metrics.getHeight().

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #8 - May 3rd, 2007 at 9:57am
Print Post  
I think I'd rather wait for next version...    Smiley
Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #9 - May 3rd, 2007 at 10:15am
Print Post  
Ok, if you wish I can upload here an updated version of the control when that method is ready.
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #10 - May 3rd, 2007 at 10:19am
Print Post  
That would be nice. Unless a new version should be out in the upcoming month - and then I prefer to use the new version.
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #11 - May 29th, 2007 at 10:03am
Print Post  
Hi,

I saw you've added the ResizeToFit metohd to Table.
What about Box? The same issue happens in Box. Is there a possibility to an automatic Resize to Box? I bet the code looks similar...  Wink
Thanks,
Yoav
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How do I create a table?
Reply #12 - May 29th, 2007 at 10:10am
Print Post  
Hi,

Roll Eyes Ok, we'll add Box.ResizeToFit too, but it will be available in the 1.2.1 release.

Stoyan
  
Back to top
 
IP Logged
 
ymoran00
Full Member
***
Offline



Posts: 163
Joined: May 2nd, 2007
Re: How do I create a table?
Reply #13 - May 29th, 2007 at 10:16am
Print Post  
Thanks - I'll be waiting.
8)

Yoav
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint