Hi,
I have the following code:
[code] package research;
import java.awt.Font; import java.awt.geom.Rectangle2D;
import javax.swing.JApplet; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea;
import app.Util.Utility; import app.Util.SAXTConstants.LocalizationConstants;
import com.mindfusion.jdiagram.Align; import com.mindfusion.jdiagram.ArrowStyle; import com.mindfusion.jdiagram.Box; import com.mindfusion.jdiagram.FitSize; import com.mindfusion.jdiagram.FlowChart; import com.mindfusion.jdiagram.GraphicsUnit; import com.mindfusion.jdiagram.RerouteArrows; import com.mindfusion.jdiagram.TextFormat;
public class Goop extends JApplet { private static final long serialVersionUID = 1L;
@Override public void init() { super.init();
flowChart = new FlowChart();
resizeTest(); }
private void initialize() { flowChart.setSelectionOnTop(false);
flowChart.setArrowStyle(ArrowStyle.Cascading); flowChart.setRouteArrows(true); flowChart.getRoutingOptions().setTriggerRerouting( RerouteArrows.WhileCreating | RerouteArrows.WhenModified);
flowChart.setMeasureUnit(GraphicsUnit.Pixel);
TextFormat textFormat = new TextFormat(Align.Center, Align.Near); textFormat.setWrapAtCharacter(true); flowChart.setTextFormat(textFormat); }
private void resizeTest() { flowChart = new FlowChart(); initialize();
JScrollPane pane = new JScrollPane(flowChart); this.getContentPane().add(pane); flowChart.setDocBounds(new Rectangle2D.Float(0, 0, 64000, 64000));
Box four = new Box(flowChart); four.setFont(new Font("Arial", 10, 10));
JTextArea area = new JTextArea(5, 10); JScrollPane pane2 = new JScrollPane(area);
int result = JOptionPane .showOptionDialog( Utility.getApplet(this), new Object[] { "Title", pane2 }, Utility .getLocalizedString(LocalizationConstants.INPUT), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { String symbolName = area.getText(); four.setText(symbolName); } four.setBounds(150, 150, 100, 100);
sizeUp(four, flowChart); flowChart.add(four); }
private FlowChart flowChart;
public void sizeUp(Box box, FlowChart canvas) { Box sizerUp = new Box(canvas);
sizerUp.setText(box.getText());
sizerUp.setFont(box.getFont());
Rectangle2D.Float stringSize = canvas.measureString(sizerUp.getText(), sizerUp.getFont());
stringSize.width = stringSize.width; stringSize.height = stringSize.height + 1;
sizerUp.setBrush(box.getBrush()); sizerUp.setPen(box.getPen()); sizerUp.setBounds(stringSize.getBounds());
sizerUp.resizeToFitText(FitSize.KeepWidth); sizerUp.resizeToFitText(FitSize.KeepHeight);
Rectangle2D.Float newBounds = sizerUp.getBounds();
box.resize(newBounds.width, newBounds.height); }
}
[/code]
I have a method written called sizeUp that resizes the box to fit the text it is given. When the applet starts, if I pass this string: [code] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [/code]
it works alright.
If I pass a very long string (>1000 characters) as this: [code] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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