Set JLabel1 in front of JLabel2 in DesktopPane1
Hi all,
i have one problem:
i habe two JLables on one DesktopPane. Now the first JLabel is meaned as background and the second JLabel should be in front of the first. At the start it works perfect, i set:
lbl2.setOpaque(true);
lbl2.setBackground(new Color(209,209,209));
// the Background is like the DesktopPane - Background.
But the problem occures when i minimize the window and maximize it again, the first label is in front of the second but this shouldn't happen.
Hope you can help.
Regards
a cup of java
package at.celix.mobili_prototyp.GUI;
import javax.swing.*;
import javax.swing.JButton;
import java.awt.event.*;
import java.awt.Color;
public class GUI {
public JFrame hptFrame = new JFrame();
private JDesktopPane dpAufriss = new JDesktopPane();
private ImageIcon icoVerlaufOben = new ImageIcon("../mobili_prototyp/images/verlauf/verlauf1.jpg");
private ImageIcon icoVerlaufMitte = new ImageIcon("../mobili_prototyp/images/verlauf/verlauf2.jpg");
private JLabel lblVerlaufOben = new JLabel();
private JLabel lblVerlaufMitte = new JLabel();
private ImageIcon icoAufrissWand = new ImageIcon("../mobili_prototyp/images/risse/Wand_Aufriss.jpg");
private JLabel lblAufrissWand = new JLabel(icoAufrissWand);
private void jbInit() throws Exception {
//Einstellungen hptFrame
hptFrame.getContentPane().setLayout(null);
hptFrame.setSize(1280, 1024);
hptFrame.setTitle("Mobili Prototyp");
hptFrame.setResizable(false);
hptFrame.setDefaultCloseOperation(2);
//Einstellungen dpAufriss
dpAufriss.setSize(1280,512);
dpAufriss.setLocation(0,0);
dpAufriss.setBackground(new Color(209,209,209));
//Einstellungen Verlauf
lblVerlaufOben.setSize(dpAufriss.getWidth(),41);
lblVerlaufMitte.setSize(dpAufriss.getWidth(),41);
lblVerlaufOben.setLocation(0,0);
lblVerlaufMitte.setLocation(0,dpAufriss.getHeight() - 41);
lblVerlaufOben.setIcon(cii.concatImageIcons(icoVerlaufOben, dpAufriss.getWidth()));
lblVerlaufMitte.setIcon(cii.concatImageIcons(icoVerlaufMitte, dpAufriss.getWidth()));
//dpAufriss add components.
dpAufriss.add(lblVerlaufMitte);
dpAufriss.add(lblVerlaufOben);
hptFrame.getContentPane().add(dpAufriss, null);
hptFrame.setVisible(true);
//ActionListener f黵 Button btnGrundriss
btnGrundriss.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lblAufrissWand.setSize(573,283);
lblGrundrissWand.setSize(595,247);
int heigthPosition = dpAufriss.getHeight()-lblAufrissWand.getHeight();
heigthPosition = dpAufriss.getHeight() - heigthPosition;
lblAufrissWand.setLocation((dpAufriss.getWidth()/2)-(lblAufrissWand.getWidth()/2), heigthPosition - 30);
lblAufrissWand.setOpaque(true);
lblAufrissWand.setBackground(new Color(209,209,209));
//lblAufrissWand.setLocation((dpAufriss.getWidth()/2)-(lblAufrissWand.getWidth()/2), dpAufriss.getHeight()-lblAufrissWand.getHeight());
lblGrundrissWand.setLocation((dpGrundriss.getWidth()/2)-(lblGrundrissWand.getWidth()/2), 50);
//lblAufrissWand.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),"Informations") );
dpAufriss.add(lblAufrissWand);
dpGrundriss.add(lblGrundrissWand);
}
});
}
public static void main(String args[]){
GUI g = new GUI();
}
}
It's not everything but the important elements are included.
Message was edited by:
a_cup_of_java