File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPanel with Border doesn't adjust JPanel's clip area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel with Border doesn Watch "JPanel with Border doesn New topic
Author

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

Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
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
Ranch Hand

Joined: Jun 13, 2009
Posts: 2157
    
    7
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

Joined: Jan 24, 2013
Posts: 23
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

Joined: May 03, 2008
Posts: 4523
    
    5

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?


luck, db
There are no new questions, but there may be new answers.
Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
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

Joined: May 03, 2008
Posts: 4523
    
    5

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
Ranch Hand

Joined: Jun 13, 2009
Posts: 2157
    
    7
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

Joined: Jan 24, 2013
Posts: 23
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
Ranch Hand

Joined: Jun 13, 2009
Posts: 2157
    
    7
Add the JTextPane to a JScrollPane. Then you can scroll the text within the scroll pane.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel with Border doesn't adjust JPanel's clip area
 
Similar Threads
JLabel Height
How can this be done (lines with panels)
swing layout button sizes
Increasing the Size of JPanel Dynamically.
Border to JPanel is displacing JPanel which has Video Component