Hello I read about Layouts but didn\'t get which one to use for my application. I want to add image to JPanel and place JLabel on op right corner just below the title bar.
A possibility with a GridBagLayout:
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel {
public MyPanel() {
setLayout(new GridBagLayout());
add(new JLabel("TOP RIGHT"), new GridBagConstraints(
0, // gridx
0, // gridy
1, // gridwidth
1, // gridheight
1, // weightx
1, // weighty
GridBagConstraints.NORTHEAST, // anchor <------------
GridBagConstraints.NONE, // fill
new Insets(0, // inset top
0, // inset left
0, // inset bottom
0), // inset right
0, // ipadx
0)); // ipady
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyPanel());
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Nicolas