How to Change the Background Jframe in Swing

How to Change the Background Jframe in Swing thumbnail
Change the background color of your Jframe.

Swing is used in conjunction with Java in order to create more sophisticated GUI (Graphical User Interface) components. One of these components, Jframe, creates a small pop-up window within the Java program, and programmers may want to change the look of that window so it matches the look and feel of the rest of their program. Inserting a few lines of code into the Jframe class component can make the entire program look more professional.

Things You'll Need

  • Java Editor
  • Jframe class within a Java file
Show More

Instructions

    • 1

      Open your preferred Java editor, such as Eclipse, DrJava or NetBeans, and select "File" from the top menu then press "Open." Find the Java file that contains a Jframe class component and double-click on it.

    • 2

      Double-click on the Jframe class from the components menu. In Netbeans, this is located on the left-hand side of the program but could differ, depending on your Java editor.

    • 3

      Add the following lines of code to the Jframe class underneath the "frame.setVisible(true);" line. Replace "white" with whatever color you want your Jframe background to be.

      Container content = f.getContentPane();
      content.setBackground(Color.white);

    • 4

      Select "File" from the top menu then press "Save."

Related Searches:

References

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured