-1

I have to write a program that displays a binary tree in a GUI. I had thought of using a simple jTree control to do the job but that would not appear to be the best way. Is there a more visually appealing way to display a binary tree?

SteveDeFacto
  • 1,205
  • 4
  • 19
  • 34
  • Is there a build component, no...You could do something like [this](http://stackoverflow.com/questions/15455739/animate-change-of-color-of-nodes-in-insertion-of-binary-search-tree/15458451#15458451) however – MadProgrammer Apr 29 '14 at 04:42

1 Answers1

1

My thought is that use render the representation of your elements in 'paint(Graphics g)' method. When you create a node in a memory, call update() method. I am talking about Swing API. You can use JFrame or other component in Swing API to render your tree element. Sample code may help you.

 @Override
 public void paint(Graphics g) {
     super.paintComponent(g);
    g.drawRect(x, y, width, height);
 }

where x, y are the locations and increment this value when you create a new tree node with respect to the width of the rectangle.

UVM
  • 9,725
  • 5
  • 40
  • 64