Hi Jythoneers,
I'm experiencing some troubles with the events dispatching in this very
first jython-test.
After the selection of the Look & Feel change and the selection of another
item in the Preferences menu , I'm not able to access the Look & Feel Menu
again.
Could anyone help me??
TIA
Stefano
from pawt import swing
import java.awt.event
message=swing.JTextField(50)
class GUI:
def __init__(self):
frame=swing.JFrame("Python
Editor",visible=1,windowClosing=self.doExit)
menuBar=swing.JMenuBar()
menuFile=swing.JMenu("File")
menuFileExit=swing.JMenuItem("Exit",java.awt.event.KeyEvent.VK_E,actionPerfo
rmed=self.doExit)
menuFile.add(menuFileExit)
menuPreferences=swing.JMenu("Preferences")
menuLookandFeel=swing.JMenu("Look&Feel")
menuLookandFeelMetal=swing.JRadioButtonMenuItem("Metal
Look&Feel",actionPerformed=self.doLookandFeel)
menuLookandFeelWindows=swing.JRadioButtonMenuItem("Windows
Look&Feel",selected=1,actionPerformed=self.doLookandFeel)
buttonGroupLookandFeel=swing.ButtonGroup()
buttonGroupLookandFeel.add(menuLookandFeelMetal)
buttonGroupLookandFeel.add(menuLookandFeelWindows)
menuPreferencesBackground=swing.JMenuItem("Background",actionPerformed=self.
refreshText)
menuPreferencesForeground=swing.JMenuItem("Foreground",actionPerformed=self.
refreshText)
menuPreferencesFont=swing.JMenuItem("Font",actionPerformed=self.refreshText)
menuLookandFeel.add(menuLookandFeelMetal)
menuLookandFeel.add(menuLookandFeelWindows)
menuPreferences.add(menuLookandFeel)
menuPreferences.add(menuPreferencesBackground)
menuPreferences.add(menuPreferencesForeground)
menuPreferences.add(menuPreferencesFont)
menuBar.add(menuFile)
menuBar.add(menuPreferences)
frame.setJMenuBar(menuBar)
panel=swing.JPanel()
panel.add(message)
frame.contentPane.add(panel)
frame.pack()
def refreshText(self,event):
message.setText(event.getSource().getText())
def doExit(self,event):
import sys
sys.exit(0)
def doLookandFeel(self,event):
lef = event.getActionCommand()
metalLF= swing.plaf.metal.MetalLookAndFeel()
windowsLF= swing.plaf.windows.WindowsLookAndFeel()
try:
if lef=="Windows Look&Feel":
swing.UIManager.setLookAndFeel(windowsLF)
#swing.SwingUtilities.updateComponentTreeUI(self)
elif lef == "Metal Look&Feel":
swing.UIManager.setLookAndFeel(metalLF)
#swing.SwingUtilities.updateComponentTreeUI(GUI)
#else:
# swing.UIManager.setLookAndFeel(motifLF)
finally:
message.setText("Look & Feel modified")
GUI()
|