本文整理汇总了Python中javax.swing.JTextArea.getCaret方法的典型用法代码示例。如果您正苦于以下问题:Python JTextArea.getCaret方法的具体用法?Python JTextArea.getCaret怎么用?Python JTextArea.getCaret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextArea
的用法示例。
在下文中一共展示了JTextArea.getCaret方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConsoleView
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import getCaret [as 别名]
class ConsoleView(JPanel):
def __init__(self, controller):
'''
Creates default empty console-looking panel.
It should be separated from the rest of the GUI so that users can choose
to show or hide the console. Or should it be a split panel?
This panel will display log and validation/lemmatization messages.
It might need its own toolbar for searching, etc.
It will also accept commands in later stages of development, if need be.
'''
# Give reference to controller to delegate action response
self.controller = controller
# Make text area occupy all available space and resize with parent window
self.setLayout(BorderLayout())
#Create console-looking area
self.editArea = JTextArea()
self.editArea.border = BorderFactory.createEmptyBorder(4,4,4,4)
self.editArea.font = Font("Courier New", Font.BOLD, 14)
self.editArea.background = Color.BLACK
self.editArea.foreground = Color.WHITE
self.editArea.text = "Console started. Nammu's log will appear here.\n\n"
# Disable writting in the console
self.editArea.setEditable(False)
# Will need scrolling controls
scrollingText = JScrollPane(self.editArea)
scrollingText.setPreferredSize(Dimension(1,150))
# Make text area auto scroll down to last printed line
caret = self.editArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
# Add to parent panel
self.add(scrollingText, BorderLayout.CENTER)
def scroll(self):
'''
Scroll down to bottom.
'''
self.editArea.setCaretPosition(self.editArea.getDocument().getLength())