• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPanel with Border doesn't adjust JPanel's clip area

 
Tim Alvord
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JPanel with a Border created by the following code:



To this I have added a JTextArea. The problem I have is that the JTextArea can be moved so that it stays on top of the Border instead of being clipped. Is there a way to have the Border area included in the JPanel's clip area?
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nest two panels. The top panel would have your Border and use a BorderLayout. Then you add your second panel containing the JTextArea to that panel.
 
Tim Alvord
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,
Are you serious? There really is no way to add a border and have the JFrame's Clip area adjusted to include the border? I did try extending the JFrame and setting the Clip myself, but this doesn't work because the JFrame's Clip Area is not permanently modified...

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Alvord wrote:Rob,
Are you serious? There really is no way to add a border and have the JFrame's Clip area adjusted to include the border?


Rob told you the way. It can't get much simpler than that.

Tim Alvord wrote:I did try extending the JFrame and setting the Clip myself, but this doesn't work because the JFrame's Clip Area is not permanently modified...


Do you usually try to do things in a convoluted way, or is this a challenge you've set to yourself?
 
Tim Alvord
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Darryl,
I just assumed a modern language like Java would behave in a way similar to .Net. when I specify a border in .Net, that area of the panel is effectively clipped. I was just suprised that Java didn't behave the same way... No need to be nasty about it.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Alvord wrote:No need to be nasty about it.



I'm sorry you perceived that as nasty. I've done a lot of stuff in various convoluted ways, just to prove to myself that the 'traditional' easy approach isn't the only approach, so I was interested to know whether this was why you were avoiding the easy solution.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I just assumed a modern language like Java would behave in a way similar to .Net.



Not sure why you would assume that. Every language works its own way.

I suggest you read A Closer Look at the Paint Mechanism to understand why Swing works the way it does.

Also, I'm not sure why you would be dragging around a JTextArea. If you use LayoutManagers then the layout manager will make sure all components are within the Border of the Component. If you do have a dragging requirement then maybe you can use the Component Mover class. It makes sure that a components is moved within the bounds of its parent.
 
Tim Alvord
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob Camick,
I have done as you suggested and it works like a charm...

What I was trying to accomplish was to construct a vertical text scroller for my About Dialog. I was doing this by moving the TextArea based on a timer. If there is another better way to do this in Java, that would be great! Otherwise, doing as you suggested works just fine...

Thanks!
 
Rob Camick
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the JTextPane to a JScrollPane. Then you can scroll the text within the scroll pane.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic