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 8126209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:04:47+00:00 2026-06-06T07:04:47+00:00

Why does the titlebar overlap the pixels of JPanel. Here some code: protected void

  • 0

Why does the titlebar overlap the pixels of JPanel. Here some code:

protected void init() {
    this.setContentPane(new MyPanel());
    this.setSize(915, 725);
    this.setVisible(true);
}

class MyPanel extends JPanel {

    @Override
    public void paintComponent(Graphics _g) {
        super.paintComponent(_g);
        Graphics2D g = (Graphics2D)_g;

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Font font = new Font("Monospaced", Font.PLAIN, 14);

        g.setFont(font);
        g.setColor(Color.red);

        for(int x=0; x<60; x++) {
            for(int y=0; y< 50; y++) {
                g.drawString("█", x*15, 0);
            }
        }
    }
}

I have added the JPanel to the JFrame and draw some String at y=0.

  • 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-06-06T07:04:48+00:00Added an answer on June 6, 2026 at 7:04 am

    y = 0 is at the top of the panel, and the coordinates grow downwards. If you want a 20-pixel high line of text to appear just at the top of the panel, then you need to draw it at y = 20. More generally, you can use the FontMetrics class to determine the height of your line of text and use an appropriate offset:

    FontMetrics metrics = _g.getFontMetrics(font);
    int lineHeight = metrics.getHeight();
    

    In your current code, you’re drawing characters (which are of the order of 20 pixels high) in the cells of a 1-pixel grid. This means that your characters will significantly overlap each other. You’ll want to step your loops by a value much greater than 1 here, to give the characters enough space.

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

Sidebar

Related Questions

Does anyone have some code that will take a TimeZoneInfo field from .NET and
Does anyone here happen to know how to accomplish this effect from Espresso.app? http://f.cl.ly/items/1j1V1q322f2K202v2T2s/ScreenFlow.mov
I have an application which does some background task (network listening & reading) in
I've been trying to work this piece of code for a week now. The
I have a Windows form which does not have a border, titlebar, menu, etc..
By the default list does not have titleBar, but when I create a list
Does anyone know how to change icons in Silverlight outofbrowser application?
Does anyone know if views states (used in Silverlight) will be available in next
Does C# allow hashtables to be populated in one-line expressions? I am thinking of
Does anyone have a nice solution for GalleryView when I want to display photos

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.