I'm trying to create an UI. After U moved everything to private and made getters and setters my JFrame
is displaying blank. For some reason I only see the basic grey window, but before that everything worked just fine.
public class Aboutus_GUI extends JFrame {
private JPanel contentPane;
private JLabel join;
private JLabel Names;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Aboutus_GUI frame = new Aboutus_GUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws MalformedURLException
*/
public Aboutus_GUI() throws MalformedURLException {
setBackground(Color.WHITE);
setTitle("About Us");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 727, 651);
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
join = new JLabel();
join.setIcon(new ImageIcon("src/GUI_final/about_us.jpg"));
join.setBounds(0, -267, 701, 770);
contentPane.add(join);
Names = new JLabel();
Names.setIcon(new ImageIcon("src/GUI_final/names.jpg"));
Names.setLocation(10, 276);
Names.setSize(887, 492);
contentPane.add(Names);
}
public JPanel getContentPane() {
return contentPane;
}
public void setContentPane(JPanel contentPane) {
this.contentPane = contentPane;
}
public JLabel getJoin() {
return join;
}
public void setJoin(JLabel join) {
this.join = join;
}
public JLabel getNames() {
return Names;
}
public void setNames(JLabel names) {
Names = names;
}
}
You don't ever actually add
contenetPane
to the frame. You just set it as a variable. As BPS commented, you prob dont want to override thesetContentPane
method. But, if you really do want to do that... Addright after
I might also suggest using a
LayoutMager
. I suggest adding:as this will make the
contentPane
take up the whole frame.