0

When i created my gui in java, i set the background color to blackish and there seems to be a pixel line of white at the right most and bottom most sections of my gui. However when i resize this gui, that like goes away and the gui is completely black. Does anyone know why this is happening? I need my gui to set resizeable to false so resizing the gui to fix this problem will not work.

package JavaQuizGameTut;
import java.awt.ActiveEvent.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
public class Quiz implements ActionListener{

    String[] questions = {
            "Which company created Java?", 
            "What year was Java created?",
            "What was java originally called?",
            "Who was credited for making java?"
        };
    String[][] options = {{"Sun Microsystems", "Starbucks", "Microsoft", "Alphabet"},
                        {"1989", "1996", "1972", "1492"},
                        {"Apple", "Latte", "Oak", "Koffing"},
                        {"Steve Jobs", "Bill Gates", "James Gosling", "Mark Zuckerburg"}
                        };
    char[] answers = {'A', 'B', 'C', 'C'};
    char guess;
    char answer;
    int index;
    int correct_guesses = 0;
    int total_questions = questions.length;
    int result;
    int seconds;

    JFrame frame = new JFrame();
    JTextField textfield = new JTextField();
    JTextArea textarea = new JTextArea();
    JButton buttonA = new JButton();
    JButton buttonB = new JButton();
    JButton buttonC = new JButton();
    JButton buttonD = new JButton();
    JLabel answer_labelA = new JLabel();
    JLabel answer_labelB = new JLabel();
    JLabel answer_labelC = new JLabel();
    JLabel answer_labelD = new JLabel();
    JLabel time_label = new JLabel();
    JLabel seconds_left = new JLabel();
    JTextField number_right = new JTextField();
    JTextField percentage = new JTextField();




    public Quiz() {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(650, 650);
        frame.getContentPane().setBackground(new Color(50, 50, 50));
        frame.setLayout(null);
        // frame.setResizable(false);

        textfield.setBounds(0, 0, 650, 50);
        textfield.setBackground(new Color(25,25, 25));
        textfield.setForeground(new Color(25, 255, 0));
        textfield.setFont(new Font("Ink Free", Font.PLAIN, 30));
        textfield.setBorder(BorderFactory.createBevelBorder(1));
        textfield.setHorizontalAlignment(JTextField.CENTER);
        textfield.setEditable(false);

        frame.add(textfield);



        frame.setVisible(true);

    }
    public void nextQuestion() {

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

    }
    public void displayAnswer() {

    }
    public void results() {

    }
}

Image of my gui

2

1 Answer 1

0

The background color does cover the entire frame only the reason you are seeing a grey bar above it is that you have placed a textfield on top of it and you have set its background colour to be grey. As in here:

textfield.setBounds(0, 0, 650, 50);
textfield.setBackground(new Color(25,25, 25));

Try changing textfield's color or temporarily commenting it and you'll see whole frame black.

If nothing fixes it then there's something wrong with your system as it is running fine in my system. See this

You can try running it in another system.

6
  • I am not concerned about seeing the black frame at the top, i purposefully put the grey bar at the top. I am concerned with the white line at the right of the gui and the bottom of it. If you look closely or zoom in, you will see it.
    – Wieniawski
    Jun 20, 2020 at 7:02
  • try setting border width to 0px and margin and padding too to 0px Jun 22, 2020 at 15:56
  • i did that, there still is that small 1px line of white.
    – Wieniawski
    Jun 23, 2020 at 1:06
  • There's something wrong with your system maybe. See the attachment in my answer Jun 23, 2020 at 11:07
  • yes, there seems to be some problem with it, i ran the code in eclipse so maybe that is why.
    – Wieniawski
    Jun 28, 2020 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.