I have an array of objects of class A that contain an array of objects of class B. I have quite a few questions: (Encoding examples will be very useful)
- How can I use
JTree
with the parent node as an object A and children of the node as B and populate it? - Assuming the entire
JFrame
split into two panels (one containing JTree
and another JPanel
that displays the attributes of the object corresponding to the option selected on JTree
), how can I do this? At the moment, I can hard code the values ββin JTree
.
I was looking for a lot of examples on the net, but I could only find basic examples.
This is what I have done so far:
public class A { int a1=10; int a2=20; B bobj[]=new B[2]; A(){ bobj[0]=new B(); bobj[1]=new B(); } } class B { int b=30; }
In my Jtree code:
import javax.swing.tree.TreeModel; public class try1 extends javax.swing.JFrame { static A a2=new A(); public try1() { initComponents(); } @SuppressWarnings("unchecked")
I found this example here 1. Since, for example, the initial format is an array of strings, they use hastable. Since I'm using an object class (A) that contains objects of B, how do I do this (I get the error message above). 2. I attached the layout of my frame. I hardcoded Jtree in the screenshot. What should I do if I click on any Jtree node, I can view the details in J
TextField next to it?
source share