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
- What does Java option -Xmx stand for? [duplicate]
- How do I convert a String to an int in Java?
- What does Java option -Xmx stand for? [duplicate]
- Is there an invisible character that is not regarded as whitespace?
- Convert hex color to RGB values in PHP
- Finding white rectangle in an image
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to convert nanoseconds to seconds using the TimeUnit enum?
- Search for words with telephone numbers from 2-3-4 tree
- Using or ‘|’ in regex [duplicate]
- How to format strings in Java
- How do I build a graphical user interface in C++? [closed]
- What is the difference between x86 and x64
- How do I build a graphical user interface in C++? [closed]
- && (AND) and || (OR) in IF statements
- How to use the toString method in Java?
- What is a NullPointerException, and how do I fix it?
- What exactly is Apache Camel?
- Unable to find valid certification path to requested target – error even after cert imported
- Unable to find valid certification path to requested target – error even after cert imported
- What is the equivalent of the C++ Pair
in Java? - Java – Convert integer to string [duplicate]
- Getting random numbers in Java [duplicate]
- What is an instance variable in Java?
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Java: “error: cannot find symbol”
- How does the Java ‘for each’ loop work?
- Which is the difference between Long.valueOf(0) and 0L in Java?
- What is a StackOverflowError?
- What are the differences between a HashMap and a Hashtable in Java?
- Use of “instanceof” in Java [duplicate]
- How to use Collections.sort() in Java?
- How to uninstall Eclipse?
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- How does System.out.print() work?
- How do I “decompile” Java class files? [closed]
- How do I determine whether an array contains a particular value in Java?