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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:29:25+00:00 2026-05-26T08:29:25+00:00

i am trying to draw some lines. Problem is about colors. For example. I

  • 0

i am trying to draw some lines. Problem is about colors. For example. I have several lines of red color, and than i draw one line of blue color (or reversed). And sometimes, that lines those is more, is opaque for that last one.

I tried to make new color and set color with alpha composite 0.7 – for those more lines, and one color i left default – opaque (alpha 1.0). At first i draw more lines, and than last one. But that lines “overwrite” that one. Is there some solution to fix this problem?

I draw that lines on glasspane.


edit: that code is robust, so it is difficult to post it, and it is one part of thesis.
principle is 2 color for example
Color basicColor;
Color similarColor;

than i have paint method and 2 hashmaps as attributes – some points are stored.
i iterate over this map, remember that one point and similar to him, all other connect with
graphics2D.drawLine(x1,y1,x2,y2) and than change color and paint last one line with another color. I am modifying stroke too, to make it more significant.

I hope it will be enough…


edit2:
i have some Point similarPoint than some robust paint method and here is graphics modifying
iterator iterate over list of points’ lists.

Point similar = null;
Iterator<Point> secondIterator;
graphics.setColor(colorOfSimilar);
while (iterator.hasNext()) {
    Point point = iterator.next();
    if (point.equals(similarPoint)) {
        similar = similarPoint;
    } else {
        secondIterator = secondMap.get(point).iterator();
        while (secondIterator.hasNext()) {
            Point secondPoint = secondIterator.next();
            graphics2D.drawLine(point.getX(), point.getY(),
                secondPoint.getX(), secondPoint.getY());
        }
    }
}
if (similar != null) {
    secondIterator = secondMap.get(similar);
    graphics2D.setColor(hooverColor);
    graphics2D.setStroke(new BasicStroke(2.5f));
    while (secondIterator.hasNext()) {
        Point secondPoint = secondIterator.next();
        graphics2D.drawLine(similar.getX(), similar.getY(),
            secondPoint.getX(), secondPoint.getY());
    }
    graphics2D.setColor(colorOfSimilar);
    graphics2D.setStroke(new BasicStroke(1.0f));
}

i wrote it in notepad so sorry about some mistakes (i think brackets etc.), but this is mechanism of modifying, around that is other methods for iterate and other, but it is not important. Problem with stroke doesn´t exist, because at first i did it without stroke.

Thanks for any idea.

  • 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-26T08:29:26+00:00Added an answer on May 26, 2026 at 8:29 am

    The result depends on which compositing rule is specified in the graphics context using setComposite(). This utility may be useful in understanding the various modes. It may also help you in preparing an sscce that exhibits the problem you describe.

    Addendum: Here’s an example that shows how one might use AlphaComposite.Src mode for this.

    enter image description here

    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    
    /** @see http://stackoverflow.com/questions/7823631 */
    public class X extends JPanel {
    
        private static final int SIZE = 300;
        private static final int INSET = 64;
        private static final AlphaComposite OVER_HALF =
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
        private boolean src;
    
        public X(boolean src) {
            this.src = src;
            this.setBackground(Color.lightGray);
        }
    
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(SIZE, SIZE);
        }
    
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            Line2D line1 = new Line2D.Double(INSET, INSET,
                getWidth() - INSET, getHeight() - INSET);
            Line2D line2 = new Line2D.Double(getWidth() - INSET,
                INSET, INSET, getHeight() - INSET);
            g2.setStroke(new BasicStroke(64,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_BEVEL));
            g2.setComposite(OVER_HALF);
            g2.setColor(Color.red);
            g2.draw(line1);
            if (src) {
                g2.setComposite(AlphaComposite.Src);
            }
            g2.setColor(Color.blue);
            g2.draw(line2);
        }
    
        public static void main(String[] args) {
            final JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new GridLayout(1, 0));
            frame.add(new X(false));
            frame.add(new X(true));
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw some simples lines with the iPhone/Touch SDK. I'd like to
I am trying to write some code that that will draw the line which
I'm trying to draw some dots connected with lines. The dot consists of the
I'm trying to draw a line using ctx.lineTo in loop. I have small function
I am trying to draw some contours that I have stored as vertex arrays:
I am trying to use the HTML5 canvas element to draw some arcs and
I am trying to draw a series of rectangles using OpenGL but some of
I'm trying to draw the pages of a PDF using the code below. Some
I have some data in mysql that I load up in php and draw
I am new to open gl, and have been trying to do some basic

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.