pontus westerfors
pontus westerfors

Reputation: 1

Javax.swing and Java.awt clashing

Im having a problem with all my code involving gui. For example the public class Ritpanel extends Jpanel line gives me an error:

getBaselineResizeBehavior()' in 'javax.swing.JComponent' clashes with 'getBaselineResizeBehavior()' in 'java.awt.Component'; attempting to use incompatible return type`

he quick fix is to implement method which do nothing. I have also tried to reinstall IntelliJ. Does anyone know whats wrong?

import javax.swing.*; import java.awt.*;

public class Ritpanel extends JPanel{

    @Override
    public void paintComponent(Graphics grafik) {
        super.paintComponent(grafik);
        grafik.setColor(Color.BLUE);
        grafik.fillRect(0,0,500,500);
        grafik.setColor(Color.YELLOW);
        grafik.fillRect(200,0,60,500);
        grafik.fillRect(0,200,500,60);

        String text = "SVERIGE!!!!";
        grafik.setColor(Color.BLACK);
        Font font = new Font("Times new Roman",Font.PLAIN,36);
        grafik.setFont(font);
        int bredd = grafik.getFontMetrics().stringWidth(text);
        grafik.drawString(text,500/2 - bredd/2,470/2 + 24/2);
    }
}

Upvotes: 0

Views: 240

Answers (2)

pontus westerfors
pontus westerfors

Reputation: 1

So the problem seemed to be a bug in my swing. My solution was to delete all settings and plugins. Then I completly reinstalled IntelliJ. This solved my problem and I no longer get this error.

Upvotes: 0

Doga Oruc
Doga Oruc

Reputation: 816

How about importing only the things you need?

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

Also, sometimes the highlighter highlights errors or warnings that aren't there. Try cleaning your project and rebuilding it.

Upvotes: 1

Related Questions