Consultor Eletrônico



Kbase 17699: Apptivity: adding a caption or label to a rectangle
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
Apptivity: adding a caption or label to a rectangle

Adding labels to Rectangles

This cannot be done from Apptivity Developer, but here is a simple
method you can add to a Form

private void addLabelToRectangle (abShape s, String label, Font font)

{
abLabel theLabel = new abLabel("Hello World", 1);
FontMetrics fm = new FontMetrics(font);
int h = fm.stringHeight();
int w = fm.stringWidth(label);
// Center the label near the upper-left corner of the Rect
// Add in 3 pixels of whitespace
Rect r = new Rect( s.x() + 5, s.y() - ( h / 2), w + 6, h );
theLabel.setFont(font);
control().addObj(theLabel, -1, Color.lightGray, Color.black, r);
}

Call this from the bottom of the "init()" method in the form.


public void init()
{
super.init();
setFont(new Font("DialogInput", Font.PLAIN, 14));

//$BEGIN_CREATE_OBJECTS
contentView().sizeTo(abUtil.lp2dp(3875), abUtil.lp2dp(2177));
Font abDefaultFont = new Font("Helvetica", Font.PLAIN, 12);
.
.
.
rectangle1 = new abShape(abShape.RECTANGLE);
addObj(rectangle1, -1L, Color.lightGray, Color.black, 2500,
750, 1125, 875);
rectangle1.setName("rectangle1");

//$END_CREATE_OBJECTS

// Code to customize data-bound controls goes here

//$BEGIN_INIT_OBJECTS
sizeTo(contentView().bounds().width + border().widthMargin(),
contentView().bounds().height + border().heightMargin());

//$END_INIT_OBJECTS

// Add rectangles here.
addLabelToRectangle (rectangle1, "Hello World", abDefaultFont);

}


Progress Software Technical Support Note # 17699