0

I have a problem with full-screen : i create a frame and put it in a full-screen Window but i see nothing but the color of the frame's background.

here is the code i used:

PB frame = new PB();

win = new Window(frame);

gs.setFullScreenWindow(win);

frame.setVisible(true);
frame.repaint();

win.repaint();

and the PB class, my frame:

 public class PB extends JFrame
{
    PB()
    {
        super();
        this.setBackground(Color.BLUE);
        this.getContentPane().add(new JButton("button"));
        JPanel jp = new JPanel();
        jp.setBackground(Color.red);
        jp.setSize(360, 200);
        this.getContentPane().add(jp);
        this.setVisible(true);
        repaint();
        pack();
    }
    @Override
    public void paint(Graphics g)
    {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(new Color(0,0,0));
        g.fillRect(0,0,200,200);
    }
}

So all i can see, is a big screen with the background color (here blue);

Thanks for all help

mKorbel
  • 109,525
  • 20
  • 134
  • 319
IonOne
  • 385
  • 4
  • 15

2 Answers2

3

I bet you didn't try your frame separately, did you?

This part of frame code:

public void paint(Graphics g)
{
    Graphics2D g2d = (Graphics2D)g;
    g2d.setPaint(new Color(0,0,0));
    g.fillRect(0,0,200,200);
}

will never let it paint its own content, just the colored rect.

So my recomendations are:

  1. Do not override JFrame's paint method - it will cause a lot of problems
  2. Just set main container panel background to the desired color
  3. Try the frame without full-screen window first to see if it displays what you need
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
Mikle Garin
  • 10,083
  • 37
  • 59
2

I think you're mis-understading the purpose of the "owner" for the Window.

JFrame extends from Window.

So, instead of saying

win = new Window(frame);
gs.setFullScreenWindow(win);

You only need to use

gs.setFullScreenWindow(frame);

Oh, and what Mikle said as well.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366