I don't believe this is possible with standard borders, mainly because a Border
is not a Container
, and so can't have other components added to it.
But, if you're willing to go for a custom border implementation, it's possible to fake a border, for example:
private class BorderFaker extends JPanel
{
public BorderFaker()
{
add( new JButton( "Faked!" ) );
}
@Override
public void paintComponent( Graphics g )
{
super.paintComponent( g );
drawFauxBorder( g );
}
private void drawFauxBorder( Graphics g )
{
g.setColor( UIManager.getColor( "border" ) );
g.drawRect( 15, 15, getWidth() - 30, getHeight() - 30 );
}
}
This shows how you could do it, but it introduces a lot of problems, such as distinguishing between components you want inside the border versus on the border (I've only hardcoded the "Faked!" button for demonstration). And you still have to organise the layout of the components relative to the "border". It would need some careful handling of components and some handy layout work - as @trashgod originally suggested.
Still, I dunno, I'd rather do something like this and fake the border than fake drawing a button. If you draw your own button, you lose compliance with the current look and feel, and unless you do all the stuff the button UI does (handle rollovers, armed state, etc), it's unlikely to look good.