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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:30:53+00:00 2026-06-06T06:30:53+00:00

I’m successfully rendering a polygon shaped window. However, I would like to outline it

  • 0

I’m successfully rendering a polygon shaped window. However, I would like to outline it with a thin stroke.

Is it possible to outline a shaped window in Java?

Here’s my working code, I’m using the componentResized method to set the shape for the window. However, if there is any other way to go in order to get the outline, both for when the Tab-Window is minimized and when the Tab-Window is maximized, please help.

//LongTab.java
//Desktop Tab

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;

public class LongTab extends JWindow implements MouseListener{

  static LongTab t;
  Boolean isVisible = false;
  final static BasicStroke stroke = new BasicStroke(2.0f);
  GeneralPath path;

  public LongTab(){
    addMouseListener(this);
    setSize(500, 1080);

    addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e){
        Polygon polygon = new Polygon();
        polygon = new Polygon();
        polygon.addPoint(40, 1080);
        polygon.addPoint(40, 700);
        polygon.addPoint(20, 690);
        polygon.addPoint(20, 400);
        polygon.addPoint(40, 390);
        polygon.addPoint(40, 0);
        polygon.addPoint(500, 0);
        polygon.addPoint(500, 1080);

        path = new GeneralPath();
        path.append(polygon, true);
        setShape(path);
      }
    });

    setSize(40, 1080);
    setLocation(1880, 0);
  } 

  public void mouseClicked (MouseEvent me) {
    if(!isVisible) {
      isVisible=true;
      t.setSize(400, 1080);
      t.setLocation(1520, 0);
      return;
    }
    if(isVisible) {
      isVisible=false;
      t.setSize(40, 1080);
      t.setLocation(1880, 0);
    }
    return;
  }

  public void mouseEntered (MouseEvent me) {
  }

  public void mousePressed (MouseEvent me) {
  }

  public void mouseReleased (MouseEvent me) {
  } 

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);     
    g2.setStroke(stroke);
    //if(!isVisible)
    //g2.draw(path);
    //repaint();
  }

  public void mouseExited (MouseEvent me) {
  }  

  public static void main (String[] args){
    SwingUtilities.invokeLater(new Runnable(){
      @Override
      public void run() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();

        //If shaped windows aren't supported, exit.
        if (!gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {
          System.err.println("Shaped windows are not supported");
          System.exit(0);
        } else {
          t = new LongTab();
          t.setVisible(true)
        }
      }
    });
  }
}
  • 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-06T06:30:55+00:00Added an answer on June 6, 2026 at 6:30 am

    I managed to figure out how to solve the problem with Java 6. It seems just simply taking out the antialias line in my paint method solves the graphic rendering glitch, where the outline isnt clean enough. Here’s the fully working code…

    Regards
    Aubrey.

     //LongTab.java
     //Desktop Tab
    
        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        import java.awt.geom.*;
        import com.sun.awt.AWTUtilities.*;
    
        public class LongTab extends JWindow implements MouseListener{
    
        static LongTab t;
        Boolean isVisible = false;
    
        GeneralPath closed;
    
        final static BasicStroke stroke = new BasicStroke(2.0f);
        GeneralPath path;
    
    
        //Constructor
        public LongTab(){
    
    
            addMouseListener(this);
            setSize(500, 1080);
    
    
        addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e){
        Polygon polygon = new Polygon();
        polygon = new Polygon();
    
        polygon.addPoint(40, 1080);
        polygon.addPoint(40, 700);
    
        polygon.addPoint(20, 690);
        polygon.addPoint(20, 400);
        polygon.addPoint(40, 390);
    
        polygon.addPoint(40, 0);
        polygon.addPoint(500, 0);
        polygon.addPoint(500, 1080);
    
    
    
        path = new GeneralPath();
        path.append(polygon, true);
        //setShape(path);
        com.sun.awt.AWTUtilities.setWindowShape(t, path);
    
        }});
    
        setSize(40, 1080);
        setLocation(1880, 0);
    
        }//end of constructor.
    
         public void mouseClicked (MouseEvent me) {
    
    
          if(!isVisible){
          isVisible=true;
          t.setSize(400, 1080);
          t.setLocation(1520, 0);
    
        return;
        }
          if(isVisible){
          isVisible=false;
          t.setSize(40, 1080);
          t.setLocation(1880, 0);
          }
          return;
    
        }
         public void mouseEntered (MouseEvent me) {}
         public void mousePressed (MouseEvent me) {}
         public void mouseReleased (MouseEvent me) {} 
         public void mouseExited (MouseEvent me) {}  
    
         public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
    
            //antialias commented out to fix outline glitch.
            //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
        g2.setStroke(stroke);
    
        g2.drawLine(40, 1080, 40, 700);
        g2.drawLine(40, 700, 20, 690);
        g2.drawLine(20, 690, 20, 400);
        g2.drawLine(20, 400, 40,390);
        g2.drawLine(40, 390, 40, 0);
    
    
    
        }
        public static void main (String[] args){
    
                    t = new LongTab();
                    t.setVisible(true);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.