• Post Reply Bookmark Topic Watch Topic
  • New Topic

i want to drawing a line,but it does not work, please help me.

 
Forman Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I build a GUI, i want to drawing a line(50,50,400,400) when i click the button. Why it does not work? How to make it work?
 
Forman Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to add JPanel to frame.like this



but why

failed?
 
Piet Souris
Rancher
Posts: 1631
36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Forman,

that's because the LayoutManager applies all the space to the center and the
south of the frame. You do not define any preferred size for your drawing
panel, so when you put it in the north position, that panel gets a size of 0.

So, my advice is:

1) give a preferredsize to your 'drawing' panel
2) do not set the size of the frame like you do it now, use 'frame.pack()'
and let the layoutmanager figure out the sizes
3) add 'super.paintComponent' in the paintComponent method of your drawing
panel.

So, to recap, this is what I made of it:


Greetz,
Piet
 
Forman Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,Piet Souris.
 
Piet Souris
Rancher
Posts: 1631
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!