Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:11:54+00:00 2026-05-30T09:11:54+00:00

This is my first attempt at using BufferStrategy and I’d really appreciate some hints.

  • 0

This is my first attempt at using BufferStrategy and I’d really appreciate some hints.

1) Why, in the below code, does getSize() return dimensions of 0 until you have resized the window? How can I detect the size of the window right away?

2) Why when getSize() is returning something is it not the full dimensions of the window? IE why is there a blackless strip to the bottom and right?

3) Is there a way to get rid of the flicker when you resize the window?

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class BSTest extends JFrame {
    BufferStrategy bs;
    DrawPanel panel = new DrawPanel();

    public BSTest() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(800,420);
        setLocationRelativeTo(null);
        setIgnoreRepaint(true);
        setVisible(true);
        createBufferStrategy(2);
        bs = getBufferStrategy();
        panel.setIgnoreRepaint(true);
        add(panel);
        panel.drawStuff();
    }

    public class DrawPanel extends JPanel {
        public void drawStuff() {
            while(true) {
                try {
                    Graphics2D g = (Graphics2D)bs.getDrawGraphics();
                    g.setColor(Color.BLACK);
                    System.out.println("W:"+getSize().width+", H:"+getSize().height);
                    g.fillRect(0,0,getSize().width,getSize().height);
                    bs.show();
                    g.dispose();
                    Thread.sleep(20);
                } catch (Exception e) { System.exit(0); }
            }
        }
     }

    public static void main(String[] args) {
        BSTest bst = new BSTest();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:11:56+00:00Added an answer on May 30, 2026 at 9:11 am
    1. The size of a JPanel is not valid until validate() has been called, typically as a result invoking pack() on the containing Window.

    2. The final size is the result of a combination of factors including the preferred sizes of the enclosed components and the panels UI delegate for a particular Look & Feel.

    3. JPanel is double buffered by default; no further effort is required. AnimationTest is an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this if my first attempt at using streaming for WCF, and I am struggling
I'm writing an application using DDD techniques. This is my first attempt at a
Although I am not new to Python, this is my first attempt at using
This is my first attempt to build a json webservice using the Tornado Framework
This is my first attempt at using Backbone.js, so I decided to make a
I'm using Visual Web Developer 2010 Express. This is my first attempt at creating
This is my first real attempt at using multithreading, I want to know how
Below is a first attempt at using a Composite pattern. It works in the
This is my first attempt at using the Google Data API, and I'm getting
This is my first attempt at using Selenium, and I am having trouble with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.