Skip to main content

Adding jlabel to canvas3d

1 reply [Last post]
Joined: 2009-11-25
Points: 0

I tried to add label to the canvas. But I couldn't able to increasse the size of the label. Please help me.

Code for label creation:

public class label extends JPanel {

JLabel tooltip;
JLabel legend;

public label()
tooltip = new JLabel("ToolTip data \n test \n");
legend = new JLabel("Legend");

setLayout(new BorderLayout(5,10));
setSize(200, 100);

public void paintComponent(Graphics g )

Adding to canvas.

setLayout(new BorderLayout());
Canvas3D canvas = createCanvas();
canvas.setSize(180, 180);
canvas.addMouseMotionListener( new ToolTipGenerator(this, 500) );
add("Center", canvas);

add("East",new label());

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-07-10
Points: 0

Your post title is confusing as the code example you give is not adding a jlabel to the canvas, but anyway...

As you might know already you cannot add swing components onto a canvas3d. In your code example you are actually adding a JPanel. I am assuming that the code below 'Adding to canvas' is in a separate class, maybe a JFrame or another JPanel. It should be ok to add a canvas3d as the center panel using BorderLayout and other swing panels for the other locations. I can't be sure but I think your code is not working because your label class is using BorderLayout but not assigning and locations for the components. Also avoid using setSize unless you have to, try setPreferredSize instead.