Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java swing border error

Tags:

java

border

swing

I am adding a java swing border into my existing code. I have referred online and put in my code which I got from a site, but on running it I get an error, and when highlighting in my intellij this pops up : cannot resolve symbol 'p'. Where am I going wrong ?

private class AnotherBorderTest extends JFrame {
    public AnotherBorderTest() {
        setTitle("Border Test");
        setSize(450, 450);

        JPanel content = (JPanel) getContentPane();
        content.setLayout(new GridLayout(6, 2, 3, 3));


        p = new JPanel();
        p.setBorder(new MatteBorder(new ImageIcon("BALL.GIF")));
        p.add(new JLabel("MatteBorder"));
        content.add(p);

        setVisible(true);
    }

    public void main(String args[]) {
        new AnotherBorderTest();
    }
}
like image 242
John Avatar asked Apr 21 '26 03:04

John


1 Answers

In your code you didn't have any value assigned to variable p. Use code

JPanel p = new JPanel(); /* instead of p = new JPanel() alone */

as it declares and assigns the variable p of type JPanel with a value of object new JPanel().

like image 97
Developer Marius Žilėnas Avatar answered Apr 22 '26 17:04

Developer Marius Žilėnas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!