0

I'm trying to add a label to my graph, but can't get it out of the default center position. This is what I have right now in my update method (it refreshes the display):

Graph<String, String> graph = getGraph();
BasicVisualizationServer<String, String> vv = getViewer(graph);
frame.getContentPane().removeAll();
frame.getContentPane().add(vv);
JLabel label = new JLabel("<html>ndp: blue<br>mdp: dark green</html>", JLabel.LEFT);
vv.add(label);
frame.pack();

It shows the label, but won't put it on the left no matter what I attach the label to or how I specify that it should be left... What am I doing wrong?

Josh
  • 6,944
  • 8
  • 41
  • 64

2 Answers2

0

Just a thought, but try programming how far from the top, bottom, left and right and adjust from there. If you are using Eclipse and the WindowBuilder, you will see the code on how it programs the position of things for starters. I believe it uses NORTH, SOUTH, EAST, WEST instead of the previous directions to place components. From there, you should be able to adjust the values (programmatically) and place the JLabel where you want it to be.

0

It's ugly, but I fixed it by just adding lots of non-breaking spaces to one row of the label content (Alt+0160), which expanded the width of the Label to be roughly the size of the window so when it is centered, the text is left-aligned. setSize() didn't work.

Josh
  • 6,944
  • 8
  • 41
  • 64