Customised button as an SVG file

Rounded Edges aren’t too difficult, though I’m not sure it’s really worth the effort, depending on the size of your project.

For posterities sake:

In the internalFrameActivated event of a window you can place this code (I put mine in a momentary button for ease of use, so this will not work as is in an internalFrame event, the code for getting a reference to the button will need to change.

from java.awt import Insets
from javax.swing.border import CompoundBorder


class RoundedBorder(CompoundBorder):
	def __init__(self,r):
		self.radius = r

	def getBorderInsets(self,c,i = None):
		return Insets(self.radius + 1, self.radius + 1,self.radius + 2, self.radius)	
			
	def getInsideBorder(self,c = None):
		return self
	
	def getOutsideBorder(self,c = None):
		return self
		
	def isBorderOpaque(self):
		return True

	def paintBorder(self,c,g,x,y,width,height):
		g.drawRoundRect(x,y,width-1,height-1,self.radius,self.radius)

#grab a reference to the button
btn = event.source.parent.getComponent('Momentary Button 1')

btn.setBorder(RoundedBorder(20))

Result:
image

Note, this is just an example, for effecting this change across multiple components you will undoubtedly want to loop through the components list of the root container and modify all of the buttons. You will probably also want a memory tag which holds the corner radius as opposed to hard coding it.

You should probably also move the code to a project script and execute it there as opposed to copying this code over and over.

Example For Loop:

comps = system.gui.getParentWindow(event).getRootContainer().getComponents()

for comp in comps:
	if isinstance(comp, JButton):
		comp.setBorder(RoundedBorder(20))

Finally, this does not take into account the background of the button, so if the background color is not transparent and the border radius gets too big, then you will see the still square corners of the background. You can of course write your own JButton class that handled all of this but again a whole lot of work for such a small thing.

This was written and tested in 8.1.7

3 Likes