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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:19:48+00:00 2026-06-01T15:19:48+00:00

I tried the following example for applying a linear gradient: GradientPaintDemo2D . It works

  • 0

I tried the following example for applying a linear gradient: GradientPaintDemo2D.

It works well, but I wanted the gradient color to be applied into Java Swing matte border. I tried this:

javax.swing.BorderFactory.createMatteBorder(1, 50, 1, 50, color)

But that’s only for applying one type of Color, not GradientPaint.

As we all know, GradientPaint contains two colors mixed altogether, as shown in the example linked above. So what’s the alternative answer for this case?

  • 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-01T15:19:50+00:00Added an answer on June 1, 2026 at 3:19 pm

    How about using new MatteBorder(int, int, int, int, javax.swing.Icon)

    //Another example:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    
    public class GradientMatteBorderTest {
      public JComponent makeUI() {
        Icon icon = new Icon() {
          @Override public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2  = (Graphics2D)g.create();
            Point2D start  = new Point2D.Float(0f, 0f);
            Point2D end    = new Point2D.Float(99f, 0f);
            float[] dist   = {0.0f, 0.5f, 1.0f};
            Color[] colors = { Color.RED, Color.YELLOW, Color.GREEN };
            g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
            g2.fillRect(x, y, 100, 10);
            g2.dispose();
          }
          @Override public int getIconWidth()  { return 100; }
          @Override public int getIconHeight() { return 10;  }
        };
        JLabel label = new JLabel("GradientMatteBorder");
        label.setBorder(BorderFactory.createMatteBorder(10,5,10,0,icon));
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
        p.add(label, BorderLayout.NORTH);
        return p;
      }
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          @Override public void run() {
            createAndShowGUI();
          }
        });
      }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new GradientMatteBorderTest().makeUI());
        f.setSize(320, 240);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I tried following example from documentation : =TEXT(WEEKDAY([Column1]), dddd) But it won't
I'm trying to break into SSE2 and tried the following example program : #include
I have tried using the obvious method as outlined in the following example but
I tried following example for a stateful session bean http://www.roseindia.net/ejb/example-of-statelfulbean.shtml , but when I
I came across the following example. I tried to google but could not find
My friend has an XML parsing example that I tried following, but it didn't
I tried following the example given on MSDN , but my code does not
In the following example (apologies for the length) I have tried to isolate some
In the following example, I tried to use uninterpreted Boolean function like (declare-const p
Following the README instructions of the jboss-as-kitchensink example , I have tried to run

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.