tags:

views:

930

answers:

1

For custom rendering purposes, I've created a class (axialPanel.java) that extends JPanel and overrides the paintComponent method. An instance of axialpanel is added to the west side of a container class set with a BorderLayout. I would like to have a few pixels of margin around the axialpanel, but setting axialpanel's border to an instance of EmptyBorder with some moderate size doesn't appear to work. Any thoughts on how I might accomplish this?

Thanks in advance.

+2  A: 

Your paintComponent method should honour the component's insets.

An easy way not to bother with that is to next your painted component inside a panel that has a border and your component as center of a BorderLayout.

(BTW: IMO it's a bad idea to extend JPanel when you don't want a panel. Just extend JComponent. There is a difference in layout and also a JPanel may or may not default to being opaque depending upon which version of which PL&F is in use (so you always need to call setOpaque unless you feel lucky).

Tom Hawtin - tackline