I've been following this tutorial on youtube on how to create a text-based adventure game. I've been following the tutorial step-by-step but unfortunately, I cannot seem to find a solution to my issue.
Here is my block of code (I've narrowed it down to the JPanel/JButton portion):
public Game() {
window = new JFrame();
window.setSize(800, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null);
con = window.getContentPane();
// button panel
buttonPanel = new JPanel();
buttonPanel.setBounds(300, 400, 200, 100);
buttonPanel.setBackground(Color.black);
//start button
pushButton = new JButton("START");
pushButton.setBackground(Color.black);
pushButton.setForeground(Color.white);
pushButton.setFont(normalFont);
pushButton.setFocusPainted(false);
buttonPanel.add(pushButton);
con.add(buttonPanel);
window.setVisible(true);
}
Here's a photo of what my button looks like: Unclicked Clicked
Some of the solutions I've tried include adding the following, both in combination and different orders:
pushButton.setContentAreaFilled(false);
pushButton.setOpaque(true);
pushButton.setOpaque(false);
pushButton.setFocusable(true);
And together:
pushButton.getBackground();
pushButton.setBackground(Color.BLACK);
But so far, none of them work or get the results I want -- which is to have a button with a BLACK background and WHITE text.
*I have been searching through Stackoverflow and other websites for an answer but so far, there seems to be no one else having similar issues as the one I am having. **I am not sure if the OS that I am using Eclipse on makes a difference or not.
Please let me know if more information needs to be provided! Thank you all in advance.