I have JPanel which contain a component imageWindow(object of this) now i want to put a label tag in the center of this imagewindow but i am not able to do so?
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new GridBagLayout());
imagePanel.add(ic); //ic is imageWindow obj
JLabel l1=new JLabel("First Label.");
JPanel example =new JPanel();
example.add(l1);
imagePanel.add(example);
what i am doing wrong here is screenshow i need to put the label here.
i want to put the label at the center but it always coming in the right side what i am doing wrong?
You could display the image in a JPanel that draws it in its paintComponent method, give that same JPanel a GridBagLayout, and add the JLabel to it. Or similarly you could display the image as an ImageIcon in a JLabel, give that JLabel a GridBagLayout, and add a text containing JLabel to it.
For instance in the code below, I display an image in the paintComponent method of a JPanel, give that panel a GridBagLayout, and then add a JLabel to that same JPanel without gridbag constraints, and this will center the JLabel on the JPanel: