> If you want to have two panels overlapping, generally you can't do that.
Of course you can:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
public class FrameTest {
public FrameTest() {
JFrame frame = new JFrame() ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("<title>") ;
frame.setContentPane(getMainPanel());
frame.setSize(400,400);
frame.setVisible(true);
}
private JPanel getMainPanel() {
Color color1 = new Color(240, 0, 0, 200);
Color color2 = new Color(0, 200, 0, 150);
JLabel label1 = new JLabel("label 1 from subPanel1");
label1.setForeground(color1);
Font font = label1.getFont().deriveFont(48f);
label1.setFont(font);
Dimension dim = label1.getPreferredSize();
JLabel label2 = new JLabel("label 2 from subPanel2");
label2.setForeground(color2);
label2.setFont(font);
JPanel subPanel1 = new JPanel();
subPanel1.setBorder(new LineBorder(color1));
subPanel1.add(label1);
subPanel1.setBounds(10, 10, dim.width + 4, dim.height + 2);
subPanel1.setOpaque(false);
JPanel subPanel2 = new JPanel();
subPanel2.setBorder(new LineBorder(color2));
subPanel2.add(label2);
subPanel2.setBounds(12, 18, dim.width + 4, dim.height + 2);
subPanel2.setOpaque(false);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(null);
mainPanel.add(subPanel1, 0);
mainPanel.add(subPanel2, 1);
return mainPanel;
}
public static void main(String[] args) {
new FrameTest();
}
}
> > > If you want to have two panels overlapping, generally you can't do that.
> >
> > Of course you can:
> Is it OP's requirement?
> I didn't presume so.
Don't feel offensed, I just wanted to correct your affirmation... If it suits the OP's requirement is not clearly defined for the moment :)
> > > > If you want to have two panels overlapping,
> generally you can't do that.
> > >
> > > Of course you can:
> > Is it OP's requirement?
> > I didn't presume so.
>
> Don't feel offensed, I just wanted to correct your
> affirmation... If it suits the OP's requirement is
> not clearly defined for the moment :)
Yeah.
You are a good man.
OP still keeps silence, though. :)