I want to make an object I can add to my java swing application.
The object when instantiated would contain an image and 2 labels – is there a way to do this using java swing?
If there is – can you point me at an example.
I.e i want
Myobj icon = new MyObj(pic, label , label);
window.addComponent(icon);
Cheers
Andy
Create a class
MyObjand let itextend JPanel. In the constructor ofMyObjyou callsetLayout(new BorderLayout())or whatever layout you prefer. Then do for instanceadd(pic, BorderLayout.NORTH); add(label1, BorderLayout.WEST); add(label2, BorderLayout.EAST);.Then you should be able to do
window.add(new MyObj(pic, label1, label2)).Produces