• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Component  RSS feed

 
John McGahee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to draw a line on a JLayeredPane (which sits on top of the content Pane of a JApplet). Now it seems like I can't draw a line using
JLayeredPane jp = new JLayeredPane();
Graphics g = jp.getGraphics();
g.drawLine(x,x,x,x);
The above code doesn't work. Do I need a custom component for drawing the line. I can add() this components to the JLayeredPane. I was thinking maybe I could write a custom component which just fills its bounds with black, and then I could initialize this component and add it on to the JLaeredPane and set its bound so it seems like a line....did anybody get that?
How do i go about doing that?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could sub-class JPanel and draw the line in the paintComponent() method... why would you want to fill the bounds of the component to draw a line? If you call setOpaque( false ) the background of the JPanel will not be drawn, only the line you draw on it...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!