本文整理汇总了Python中javax.swing.JTextField.addFocusListener方法的典型用法代码示例。如果您正苦于以下问题:Python JTextField.addFocusListener方法的具体用法?Python JTextField.addFocusListener怎么用?Python JTextField.addFocusListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextField
的用法示例。
在下文中一共展示了JTextField.addFocusListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: textfield
# 需要导入模块: from javax.swing import JTextField [as 别名]
# 或者: from javax.swing.JTextField import addFocusListener [as 别名]
def textfield(text = "", actionListener = None):
txt = JTextField(text, 15)
class Focuser(FocusListener):
def focusGained(self,e):
pass
def focusLost(self,e):
if actionListener: actionListener(e)
txt.addFocusListener(Focuser())
# if actionListener: txt.addActionListener(actionListener)
return txt
示例2: ConsolePanel
# 需要导入模块: from javax.swing import JTextField [as 别名]
# 或者: from javax.swing.JTextField import addFocusListener [as 别名]
class ConsolePanel(Panel):
def __init__(self):
self.console = None
self.outText = None
self.inText = None
self.outTextScroller = None
self.nestedInputPanel = None
self.directoryText = None
Panel.__init__(self, "insets 0 0 0 0")
def sendCommand(self, command):
print str(self)
oldText = self.inText.getText()
self.inText.setText(command)
self.inText.getActionListeners()[0].actionPerformed(None)
self.inText.setText(oldText)
def setDirectoryText(self, dirText):
self.directoryText.setText(dirText)
self.nestedInputPanel.revalidate()
def write_out(self,text):
if not self.outText:
return
self.outText.setText(self.outText.getText() + text)
def initUI(self):
font = Font("Courier New", Font.BOLD, 14)
#create the output text panel
self.outText = JTextArea()
self.outText.setEditable(False)
self.outText.setFont(font)
self.outText.setWrapStyleWord(True)
self.outText.setLineWrap(True)
#self.outText.setLineWrap(True)
#self.outText.setWrapStyleWord(True)
class NoGhostScroller(JScrollPane):
def paintComponent(self, g):
g.setColor(self.getBackground())
g.fillRect(0, 0, self.getWidth(), self.getHeight())
#super(NoGhostScroller, self).paintComponent(g)
self.outTextScroller = JScrollPane(self.outText)
self.outTextScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)
self.outTextScroller.getVerticalScrollBar().setForeground(Color(255, 0, 0))
#self.outText.setOpaque(False)
self.outText.setBackground(Color(0, 20, 0))
self.outText.setForeground(Color.WHITE)
#self.outTextScroller.setOpaque(False)
self.outTextScroller.setBackground(Color(0, 20, 0))
#self.outText.repaint()
#self.layered = JLayeredPane()
#self.layered.setLayer(self.outTextScroller, 0)
#create the input text box
self.inText = JTextField()
self.inText.setFocusTraversalKeysEnabled(False)
self.inText.setFont(font)
self.inText.setBackground(Color(0, 20, 0))
self.inText.setForeground(Color.WHITE)
self.inText.getCaret().setVisible(True)
self.inText.getCaret().setBlinkRate(500)
self.inText.setCaretColor(Color(200,255,200))
class InFocusAdapter(FocusAdapter):
def focusLost(adap, e):
self.inText.setVisible(True)
self.inText.addFocusListener(InFocusAdapter())
self.nestedInputPanel = Panel("Insets 0 0 0 0")
#create the directory text box
self.directoryText = JTextField()
self.directoryText.setEditable(False)
self.directoryText.setFont(font)
self.directoryText.setBackground(Color(0, 20, 0))
self.directoryText.setForeground(Color.WHITE)
#set up the console
sys.stdout = FakeOut(self.outText)
self.console = BashED_Console(stdout=sys.stdout)
self.directoryText.setText(self.console.get_prompt())
self.revalidate();
dirTex = self.directoryText;
#create the listener that fires when the 'return' key is pressed
class InputTextActionListener(ActionListener):
def __init__(self,parent,inp,out,console):
self.parent = parent
self.inp = inp
#.........这里部分代码省略.........