How to change color of lines in each iteration of a for loop in JavaHow do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?A 'for' loop to iterate over an enum in JavaHow do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How do I convert a String to an int in Java?
If your plane is out-of-control, why does military training instruct releasing the joystick to neutralize controls?
Managing and organizing the massively increased number of classes after switching to SOLID?
If a non-friend comes across my Steam Wishlist, how easily can he gift me one of the games?
US Civil War story: man hanged from a bridge
Constructive proof of existence of free algebras for infinitary equational theories
The monorail explodes before I can get on it
What explains 9 speed cassettes price differences?
Are there any sports for which the world's best player is female?
How would my creatures handle groups without a strong concept of numbers?
Print the last, middle and first character of your code
Need help identifying planes, near Toronto
Are randomly-generated passwords starting with "a" less secure?
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
Multiple DUI convictions 12 years ago. Do I disclose if I know they will do a background check?
Why did Harry Potter get a bedroom?
Why do players in the past play much longer tournaments than today's top players?
Why were Er and Onan punished if they were under 20?
Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?
Received a dinner invitation through my employer's email, is it ok to attend?
As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?
Why does it output Integers instead of letters?
Did the Vulgar Latin verb "toccare" exist?
definition of "percentile"
Is anyone advocating the promotion of homosexuality in UK schools?
How to change color of lines in each iteration of a for loop in Java
How do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?A 'for' loop to iterate over an enum in JavaHow do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How do I convert a String to an int in Java?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an ArrayList called theLayers
which stores collections of points (layers), and I would like each layer to have a distinct color. At each iteration of the for loop I set the graphics to a new color and draw the points of each distinct layer. However, upon debugging, I have noticed that the points are set to the last color that was generated.
I have tried placing the random color assignment at different locations in the code, and I have debugged the code to ensure that the colors are indeed being changed during each iteration.
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;
public class Drawer extends JPanel
private ArrayList<ArrayList<Point>> theLayers;
public Drawer()
this(new ArrayList<ArrayList<Point>>());
public Drawer(ArrayList<ArrayList<Point>> coordinates)
this.theLayers = new ArrayList<ArrayList<Point>>(coordinates);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<Point> coordinates:theLayers)
int R = (int) (Math.random( )*256);
int G = (int)(Math.random( )*256);
int B= (int)(Math.random( )*256);
Color randomColor = new Color(R, G, B);
g2d.setColor(randomColor);
for (int i = 0; i < coordinates.size(); i++)
g2d.drawLine(coordinates.get(i).x, coordinates.get(i).y,
coordinates.get(i).x, coordinates.get(i).y);
I want the color of each layer to be distinct, not the same color. Thank you.
java swing colors
add a comment |
I have an ArrayList called theLayers
which stores collections of points (layers), and I would like each layer to have a distinct color. At each iteration of the for loop I set the graphics to a new color and draw the points of each distinct layer. However, upon debugging, I have noticed that the points are set to the last color that was generated.
I have tried placing the random color assignment at different locations in the code, and I have debugged the code to ensure that the colors are indeed being changed during each iteration.
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;
public class Drawer extends JPanel
private ArrayList<ArrayList<Point>> theLayers;
public Drawer()
this(new ArrayList<ArrayList<Point>>());
public Drawer(ArrayList<ArrayList<Point>> coordinates)
this.theLayers = new ArrayList<ArrayList<Point>>(coordinates);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<Point> coordinates:theLayers)
int R = (int) (Math.random( )*256);
int G = (int)(Math.random( )*256);
int B= (int)(Math.random( )*256);
Color randomColor = new Color(R, G, B);
g2d.setColor(randomColor);
for (int i = 0; i < coordinates.size(); i++)
g2d.drawLine(coordinates.get(i).x, coordinates.get(i).y,
coordinates.get(i).x, coordinates.get(i).y);
I want the color of each layer to be distinct, not the same color. Thank you.
java swing colors
1
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out theDrawOnComponent
example from Custom Painting Approaches for a working example of this approach.
– camickr
Mar 26 at 2:55
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38
add a comment |
I have an ArrayList called theLayers
which stores collections of points (layers), and I would like each layer to have a distinct color. At each iteration of the for loop I set the graphics to a new color and draw the points of each distinct layer. However, upon debugging, I have noticed that the points are set to the last color that was generated.
I have tried placing the random color assignment at different locations in the code, and I have debugged the code to ensure that the colors are indeed being changed during each iteration.
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;
public class Drawer extends JPanel
private ArrayList<ArrayList<Point>> theLayers;
public Drawer()
this(new ArrayList<ArrayList<Point>>());
public Drawer(ArrayList<ArrayList<Point>> coordinates)
this.theLayers = new ArrayList<ArrayList<Point>>(coordinates);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<Point> coordinates:theLayers)
int R = (int) (Math.random( )*256);
int G = (int)(Math.random( )*256);
int B= (int)(Math.random( )*256);
Color randomColor = new Color(R, G, B);
g2d.setColor(randomColor);
for (int i = 0; i < coordinates.size(); i++)
g2d.drawLine(coordinates.get(i).x, coordinates.get(i).y,
coordinates.get(i).x, coordinates.get(i).y);
I want the color of each layer to be distinct, not the same color. Thank you.
java swing colors
I have an ArrayList called theLayers
which stores collections of points (layers), and I would like each layer to have a distinct color. At each iteration of the for loop I set the graphics to a new color and draw the points of each distinct layer. However, upon debugging, I have noticed that the points are set to the last color that was generated.
I have tried placing the random color assignment at different locations in the code, and I have debugged the code to ensure that the colors are indeed being changed during each iteration.
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;
public class Drawer extends JPanel
private ArrayList<ArrayList<Point>> theLayers;
public Drawer()
this(new ArrayList<ArrayList<Point>>());
public Drawer(ArrayList<ArrayList<Point>> coordinates)
this.theLayers = new ArrayList<ArrayList<Point>>(coordinates);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<Point> coordinates:theLayers)
int R = (int) (Math.random( )*256);
int G = (int)(Math.random( )*256);
int B= (int)(Math.random( )*256);
Color randomColor = new Color(R, G, B);
g2d.setColor(randomColor);
for (int i = 0; i < coordinates.size(); i++)
g2d.drawLine(coordinates.get(i).x, coordinates.get(i).y,
coordinates.get(i).x, coordinates.get(i).y);
I want the color of each layer to be distinct, not the same color. Thank you.
java swing colors
java swing colors
asked Mar 26 at 2:37
HossmeisterHossmeister
1093 bronze badges
1093 bronze badges
1
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out theDrawOnComponent
example from Custom Painting Approaches for a working example of this approach.
– camickr
Mar 26 at 2:55
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38
add a comment |
1
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out theDrawOnComponent
example from Custom Painting Approaches for a working example of this approach.
– camickr
Mar 26 at 2:55
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38
1
1
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1
1
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out the
DrawOnComponent
example from Custom Painting Approaches for a working example of this approach.– camickr
Mar 26 at 2:55
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out the
DrawOnComponent
example from Custom Painting Approaches for a working example of this approach.– camickr
Mar 26 at 2:55
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38
add a comment |
1 Answer
1
active
oldest
votes
As explained by camickr have a custom point object that has color attribute:
class ColoredPoint extends Point
private final Color color;
ColoredPoint(int x, int y,Color color)
super(x, y);
this.color = color;
Color getColor()
return color;
And use it in Drawer
class :
class Drawer extends JPanel
private final ArrayList<ArrayList<ColoredPoint>> theLayers;
private static final int W = 700, H =700;
public Drawer()
this(new ArrayList<ArrayList<ColoredPoint>>());
public Drawer(ArrayList<ArrayList<ColoredPoint>> coordinates)
theLayers = new ArrayList<>(coordinates);
setPreferredSize(new Dimension(W,H));
@Override
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<ColoredPoint> cPoints:theLayers)
g2d.setColor(cPoints.get(0).getColor());
for (int i = 0; i < cPoints.size(); i++)
g2d.drawLine(cPoints.get(i).x, cPoints.get(i).y,
cPoints.get(i).x, cPoints.get(i).y);
Use this link for an mcve. Copy paste the entire code into one file (SwingTestFrame.java) and run.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349066%2fhow-to-change-color-of-lines-in-each-iteration-of-a-for-loop-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As explained by camickr have a custom point object that has color attribute:
class ColoredPoint extends Point
private final Color color;
ColoredPoint(int x, int y,Color color)
super(x, y);
this.color = color;
Color getColor()
return color;
And use it in Drawer
class :
class Drawer extends JPanel
private final ArrayList<ArrayList<ColoredPoint>> theLayers;
private static final int W = 700, H =700;
public Drawer()
this(new ArrayList<ArrayList<ColoredPoint>>());
public Drawer(ArrayList<ArrayList<ColoredPoint>> coordinates)
theLayers = new ArrayList<>(coordinates);
setPreferredSize(new Dimension(W,H));
@Override
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<ColoredPoint> cPoints:theLayers)
g2d.setColor(cPoints.get(0).getColor());
for (int i = 0; i < cPoints.size(); i++)
g2d.drawLine(cPoints.get(i).x, cPoints.get(i).y,
cPoints.get(i).x, cPoints.get(i).y);
Use this link for an mcve. Copy paste the entire code into one file (SwingTestFrame.java) and run.
add a comment |
As explained by camickr have a custom point object that has color attribute:
class ColoredPoint extends Point
private final Color color;
ColoredPoint(int x, int y,Color color)
super(x, y);
this.color = color;
Color getColor()
return color;
And use it in Drawer
class :
class Drawer extends JPanel
private final ArrayList<ArrayList<ColoredPoint>> theLayers;
private static final int W = 700, H =700;
public Drawer()
this(new ArrayList<ArrayList<ColoredPoint>>());
public Drawer(ArrayList<ArrayList<ColoredPoint>> coordinates)
theLayers = new ArrayList<>(coordinates);
setPreferredSize(new Dimension(W,H));
@Override
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<ColoredPoint> cPoints:theLayers)
g2d.setColor(cPoints.get(0).getColor());
for (int i = 0; i < cPoints.size(); i++)
g2d.drawLine(cPoints.get(i).x, cPoints.get(i).y,
cPoints.get(i).x, cPoints.get(i).y);
Use this link for an mcve. Copy paste the entire code into one file (SwingTestFrame.java) and run.
add a comment |
As explained by camickr have a custom point object that has color attribute:
class ColoredPoint extends Point
private final Color color;
ColoredPoint(int x, int y,Color color)
super(x, y);
this.color = color;
Color getColor()
return color;
And use it in Drawer
class :
class Drawer extends JPanel
private final ArrayList<ArrayList<ColoredPoint>> theLayers;
private static final int W = 700, H =700;
public Drawer()
this(new ArrayList<ArrayList<ColoredPoint>>());
public Drawer(ArrayList<ArrayList<ColoredPoint>> coordinates)
theLayers = new ArrayList<>(coordinates);
setPreferredSize(new Dimension(W,H));
@Override
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<ColoredPoint> cPoints:theLayers)
g2d.setColor(cPoints.get(0).getColor());
for (int i = 0; i < cPoints.size(); i++)
g2d.drawLine(cPoints.get(i).x, cPoints.get(i).y,
cPoints.get(i).x, cPoints.get(i).y);
Use this link for an mcve. Copy paste the entire code into one file (SwingTestFrame.java) and run.
As explained by camickr have a custom point object that has color attribute:
class ColoredPoint extends Point
private final Color color;
ColoredPoint(int x, int y,Color color)
super(x, y);
this.color = color;
Color getColor()
return color;
And use it in Drawer
class :
class Drawer extends JPanel
private final ArrayList<ArrayList<ColoredPoint>> theLayers;
private static final int W = 700, H =700;
public Drawer()
this(new ArrayList<ArrayList<ColoredPoint>>());
public Drawer(ArrayList<ArrayList<ColoredPoint>> coordinates)
theLayers = new ArrayList<>(coordinates);
setPreferredSize(new Dimension(W,H));
@Override
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3));
for(ArrayList<ColoredPoint> cPoints:theLayers)
g2d.setColor(cPoints.get(0).getColor());
for (int i = 0; i < cPoints.size(); i++)
g2d.drawLine(cPoints.get(i).x, cPoints.get(i).y,
cPoints.get(i).x, cPoints.get(i).y);
Use this link for an mcve. Copy paste the entire code into one file (SwingTestFrame.java) and run.
answered Mar 26 at 6:53
c0derc0der
10.4k5 gold badges19 silver badges48 bronze badges
10.4k5 gold badges19 silver badges48 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349066%2fhow-to-change-color-of-lines-in-each-iteration-of-a-for-loop-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code.
– Andrew Thompson
Mar 26 at 2:50
1
You should NOT be generating random colors in the paintComponent() method. You can't control when Swing determines a components needs to be repainted. The color should be randomized and stored in the ArrayList as you add each object to the ArrayList. This means you need a custom object that contains the color and the object you want painted. Check out the
DrawOnComponent
example from Custom Painting Approaches for a working example of this approach.– camickr
Mar 26 at 2:55
@camickr I did as you said and created a custom object... but this did not resolve my issue.
– Hossmeister
Mar 26 at 3:26
@Hossmeister, 1) where is your minimal reproducible example demonstrating the problem? 2) How do you expect us to help if we can't see the code? 3) but more importantly you need to learn how to debug your own code, so how is your code different than the working example code you were given?
– camickr
Mar 26 at 14:38