JMenuItem Antialias

There’s a bug within the Jython interpreter. You can use the automatically-created super__ method to directly call the super method; super() should work but doesn’t:

from java.awt import RenderingHints
from java.awt import Toolkit
from java.util import Map
from javax.swing import JMenuItem, JComponent

from functools import partial

class antiAliasedJMI(JMenuItem):
	def paintComponent(self, g):
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,	RenderingHints.VALUE_ANTIALIAS_ON)
		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
		g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON)
		self.super__paintComponent(g)


a = antiAliasedJMI("text", None, action=partial(system.gui.messageBox, "title", "message"))

menu = system.gui.createPopupMenu([],[])

menu.add(a)

menu.show(event)

Also, I don’t think you need to override init, which makes it all feel a little less “magic”.

4 Likes