You have added the JPanel
over the JFrame
which completely blocks out the underlying container on which you have set the color.
You could do this instead:
public Gui(String title) { super(title); JPanel pane = new JPanel(); setBounds(100, 100, 500, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container con = this.getContentPane(); pane.setBackground(new Color(0, 0, 0)); con.add(pane); setVisible(true); }
Related Posts:
- Resizing image in Java
- How do you add an ActionListener onto a JButton in Java
- KeyPressed event in java
- Difference between java.exe and javaw.exe
- Getting a HeadlessException: No X11 DISPLAY variable was set
- Simple Java 2D graphics: draw a rectangle?
- JOptionPane YES NO OPTION
- Java: Difference between the setPreferredSize() and setSize() methods in components
- How to center the text in a JLabel?
- addMouseListener for a JPanel
- How to make PopUp window in java
- JFrame in full screen Java
- Java: Custom Buttons in showInputDialog
- make a JLabel wrap it’s text by setting a max width
- the getSource() and getActionCommand()
- java.awt.EventQueue.invokeLater explained
- DTO and DAO concepts and MVC
- Setting background color for a JFrame
- Adding a Scrollable JTextArea (Java)
- How can I set size of a button?
- Problem with gif with transparent background
- How change the color arrowIcon to JMenu when it is selected
- error upon assigning Layout: BoxLayout can’t be shared
- possible lossy conversion from long to int?
- trying to fix java Exception in thread “JavaFX Application Thread” java.lang.NullPointerException
- How do I draw a triangle?
- Java: Rotating Images
- Simple Dropdown menu in Java
- How do I draw a triangle?
- repaint() Method in Java
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- Java GUI: about getContentPane( ) method and content
- How to add an image to a JPanel?
- How to repaint a JPanel after have drawn on it?
- Implementing an actionlistener to a JTextField
- How to Set JPanel’s Width and Height?
- Java Wait for thread to finish
- Swing/Java: How to use the getText and setText string properly
- What does super.paintComponent(g) do?
- Android Color Picker
- How to Set the Background Color of a JButton on the Mac OS
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- Popup Message boxes
- Exception in thread “AWT-EventQueue-0”?
- Understanding BufferedImage.getRGB output values
- Keylistener not working for JPanel
- setMnemonic() and call a method by pressing the key
- How to programmatically close a JFrame
- How does addNotify() and requestFocus() work in Java with JPanel?
- Adding JPanel to JFrame
- Adding image to JFrame
- How to Retrieve value from JTextField in Java Swing?
- What does .pack() do?
- Setting background images in JFrame
- Java Swing revalidate() vs repaint()
- Use CSS in Java Applications
- How does paintComponent work?
- Java Swing setting JPanel Size
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- set background color: Android
- set background color: Android
- JOptionPane Yes or No window
- java.net.ConnectException: Connection refused
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- Exception in thread “main” java.lang.Error: Unresolved compilation problems
- Round a double to 2 decimal places [duplicate]
- Int division: Why is the result of 1/3 == 0?
- Given final block not properly padded
- Difference between HashMap and Map in Java..?
- javac not working in windows command prompt
- Java returns error “Cannot instantiate the type”
- java.io.IOException: Broken pipe
- How to execute a https GET request from java
- Using NotNull Annotation in method argument
- How to implement infinity in Java?
- Java Does Not Equal (!=) Not Working?
- How to represent empty char in Java Character class
- Definition of a Java Container
- “The public type <
> must be defined in its own file” error in Eclipse [duplicate] - How to calculate the intersection of two sets?
- method does not override method in its superclass
- Adding a timer to my program (javafx)
- How to resolve “Syntax error on token “else”” in Java?
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 exception
- What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL?
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- Union or intersection of Java Sets
- Get an OutputStream into a String
- Difference between string object and string literal
- Python-like list comprehension in Java
- Can an int be null in Java?
- What’s the difference between HashSet and Set?
- Netbeans – Error: Could not find or load main class
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- Why int[] a = new int[1] instead of just int a?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- Prevent Selected Terms Rising to the Top
- How to write files in hosting in admin dashboard?
- Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges