本文整理汇总了Python中javax.swing.JTextArea.setCaretPosition方法的典型用法代码示例。如果您正苦于以下问题:Python JTextArea.setCaretPosition方法的具体用法?Python JTextArea.setCaretPosition怎么用?Python JTextArea.setCaretPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextArea
的用法示例。
在下文中一共展示了JTextArea.setCaretPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConversationWindow
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
class ConversationWindow(Conversation):
"""A GUI window of a conversation with a specific person"""
def __init__(self, person, chatui):
"""ConversationWindow(basesupport.AbstractPerson:person)"""
Conversation.__init__(self, person, chatui)
self.mainframe = JFrame("Conversation with "+person.name)
self.display = JTextArea(columns=100,
rows=15,
editable=0,
lineWrap=1)
self.typepad = JTextField()
self.buildpane()
self.lentext = 0
def buildpane(self):
buttons = JPanel(doublebuffered)
buttons.add(JButton("Send", actionPerformed=self.send))
buttons.add(JButton("Hide", actionPerformed=self.hidewindow))
mainpane = self.mainframe.getContentPane()
mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS))
mainpane.add(JScrollPane(self.display))
self.typepad.actionPerformed = self.send
mainpane.add(self.typepad)
mainpane.add(buttons)
def show(self):
self.mainframe.pack()
self.mainframe.show()
def hide(self):
self.mainframe.hide()
def sendText(self, text):
self.displayText("\n"+self.person.client.name+": "+text)
Conversation.sendText(self, text)
def showMessage(self, text, metadata=None):
self.displayText("\n"+self.person.name+": "+text)
def contactChangedNick(self, person, newnick):
Conversation.contactChangedNick(self, person, newnick)
self.mainframe.setTitle("Conversation with "+newnick)
#GUI code
def displayText(self, text):
self.lentext = self.lentext + len(text)
self.display.append(text)
self.display.setCaretPosition(self.lentext)
#actionlisteners
def hidewindow(self, ae):
self.hide()
def send(self, ae):
text = self.typepad.getText()
self.typepad.setText("")
if text != "" and text != None:
self.sendText(text)
示例2: ConsoleView
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [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())
示例3: Tip
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
class Tip(JWindow):
"""
Window which provides the user with information about the method.
For Python, this shows arguments, and the documention
For Java, this shows the signature(s) and return type
"""
MAX_HEIGHT = 300
MAX_WIDTH = 400
def __init__(self, frame):
JWindow.__init__(self, frame)
self.textarea = JTextArea()
# TODO put this color with all the other colors
self.textarea.setBackground(Color(225,255,255))
self.textarea.setEditable(0)
self.jscrollpane = JScrollPane(self.textarea)
self.getContentPane().add(self.jscrollpane)
def setText(self, tip):
self.textarea.setText(tip)
self.textarea.setCaretPosition(0)
#print >> sys.stderr, self.textarea.getPreferredScrollableViewportSize()
self.setSize(self.getPreferredSize())
def getPreferredSize(self):
# need to add a magic amount to the size to avoid scrollbars
# I'm sure there's a better way to do this
MAGIC = 20
size = self.textarea.getPreferredScrollableViewportSize()
height = size.height + MAGIC
width = size.width + MAGIC
if height > Tip.MAX_HEIGHT:
height = Tip.MAX_HEIGHT
if width > Tip.MAX_WIDTH:
width = Tip.MAX_WIDTH
return Dimension(width, height)
def showTip(self, tip, displayPoint):
self.setLocation(displayPoint)
self.setText(tip)
self.show()
示例4: JythonGui
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
#.........这里部分代码省略.........
self.logScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS)
self.logScrollBar = self.logScrollPane.getVerticalScrollBar()
self.log_panel.add(self.logScrollPane, BorderLayout.CENTER)
# File selectors
self.inputChooser = JFileChooser()
self.inputChooser.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
self.outputChooser = JFileChooser()
defaultOutputFile = os.path.join(System.getProperty("user.home"),
"sasi_project.zip")
self.outputChooser.setSelectedFile(File(defaultOutputFile));
self.outputChooser.fileSelectionMode = JFileChooser.FILES_ONLY
self.frame.setLocationRelativeTo(None)
self.frame.visible = True
def browseInstructions(self, event):
""" Open a browser to the instructions page. """
browseURI(self.instructionsURI)
def itemStateChanged(self, event):
""" Listen for checkbox changes. """
checkBox = event.getItemSelectable()
is_selected = (event.getStateChange() == ItemEvent.SELECTED)
result_field = self.resultFieldCheckBoxes[checkBox]
self.selected_result_fields[result_field['id']] = is_selected
def log_msg(self, msg):
""" Print message to log and scroll to bottom. """
self.log.append(msg + "\n")
self.log.setCaretPosition(self.log.getDocument().getLength())
def openInputChooser(self, event):
ret = self.inputChooser.showOpenDialog(self.frame)
if ret == JFileChooser.APPROVE_OPTION:
self.selected_input_file = self.inputChooser.selectedFile
self.log_msg("Selected '%s' as input." % self.selected_input_file.path)
def openOutputChooser(self, event):
ret = self.outputChooser.showSaveDialog(self.frame)
if ret == JFileChooser.APPROVE_OPTION:
selectedPath = self.outputChooser.selectedFile.path
if not selectedPath.endswith('.zip'):
zipPath = selectedPath + '.zip'
self.outputChooser.setSelectedFile(File(zipPath))
self.selected_output_file = self.outputChooser.selectedFile
self.log_msg(
"Selected '%s' as output." % self.selected_output_file.path)
def runSASI(self, event):
try:
self.validateParameters()
except Exception as e:
self.log_msg("ERROR: '%s'" % e)
# Run task in a separate thread, so that log
# messages will be shown as task progresses.
def run_task():
self.tmp_dir = tempfile.mkdtemp(prefix="sasi_runner.")
self.db_file = os.path.join(self.tmp_dir, "sasi_runner.db")
self.progressBar.setValue(0)
self.progressBar.setIndeterminate(True)
示例5: JythonGui
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
class JythonGui(object):
def __init__(self, instructionsURI=""):
self.instructionsURI = instructionsURI
self.logger = logging.getLogger("sasi_gridder_gui")
self.logger.addHandler(logging.StreamHandler())
def log_fn(msg):
self.log_msg(msg)
self.logger.addHandler(FnLogHandler(log_fn))
self.logger.setLevel(logging.DEBUG)
self.selected_input_file = None
self.selected_output_file = None
self.frame = JFrame("SASI Gridder", defaultCloseOperation=WindowConstants.EXIT_ON_CLOSE)
self.frame.size = (650, 600)
self.main_panel = JPanel()
self.main_panel.layout = BoxLayout(self.main_panel, BoxLayout.Y_AXIS)
self.frame.add(self.main_panel)
self.top_panel = JPanel(SpringLayout())
self.top_panel.alignmentX = Component.CENTER_ALIGNMENT
self.main_panel.add(self.top_panel)
self.stageCounter = 1
def getStageLabel(txt):
label = JLabel("%s. %s" % (self.stageCounter, txt))
self.stageCounter += 1
return label
# Instructions link.
self.top_panel.add(getStageLabel("Read the instructions:"))
instructionsButton = JButton(
('<HTML><FONT color="#000099">' "<U>open instructions</U></FONT><HTML>"),
actionPerformed=self.browseInstructions,
)
instructionsButton.setHorizontalAlignment(SwingConstants.LEFT)
instructionsButton.setBorderPainted(False)
instructionsButton.setOpaque(False)
instructionsButton.setBackground(Color.WHITE)
instructionsButton.setToolTipText(self.instructionsURI)
self.top_panel.add(instructionsButton)
# Select input elements.
self.top_panel.add(getStageLabel("Select an input data folder:"))
self.top_panel.add(JButton("Select input...", actionPerformed=self.openInputChooser))
# Select output elements.
self.top_panel.add(getStageLabel("Specify an output file:"))
self.top_panel.add(JButton("Specify output...", actionPerformed=self.openOutputChooser))
# Run elements.
self.top_panel.add(getStageLabel("Run SASI Gridder: (this might take a hwile"))
self.run_button = JButton("Run...", actionPerformed=self.runSASIGridder)
self.top_panel.add(self.run_button)
SpringUtilities.makeCompactGrid(self.top_panel, self.stageCounter - 1, 2, 6, 6, 6, 6)
# Progress bar.
self.progressBar = JProgressBar(0, 100)
self.main_panel.add(self.progressBar)
# Log panel.
self.log_panel = JPanel()
self.log_panel.alignmentX = Component.CENTER_ALIGNMENT
self.log_panel.setBorder(EmptyBorder(10, 10, 10, 10))
self.main_panel.add(self.log_panel)
self.log_panel.setLayout(BorderLayout())
self.log = JTextArea()
self.log.editable = False
self.logScrollPane = JScrollPane(self.log)
self.logScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS)
self.log_panel.add(self.logScrollPane, BorderLayout.CENTER)
# File selectors
self.inputChooser = JFileChooser()
self.inputChooser.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
self.outputChooser = JFileChooser()
self.outputChooser.fileSelectionMode = JFileChooser.FILES_ONLY
defaultOutputFile = os.path.join(System.getProperty("user.home"), "gridded_efforts.csv")
self.outputChooser.setSelectedFile(File(defaultOutputFile))
self.frame.setLocationRelativeTo(None)
self.frame.visible = True
def browseInstructions(self, event):
""" Open a browser to the instructions page. """
browseURI(self.instructionsURI)
return
def log_msg(self, msg):
self.log.append(msg + "\n")
self.log.setCaretPosition(self.log.getDocument().getLength())
def openInputChooser(self, event):
ret = self.inputChooser.showOpenDialog(self.frame)
#.........这里部分代码省略.........
示例6: GroupConversationWindow
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
class GroupConversationWindow(GroupConversation):
"""A GUI window of a conversation witha group of people"""
def __init__(self, group, chatui):
GroupConversation.__init__(self, group, chatui)
self.mainframe = JFrame(self.group.name)
self.headers = ["Member"]
self.memberdata = UneditableTableModel([], self.headers)
self.display = JTextArea(columns=100, rows=15, editable=0, lineWrap=1)
self.typepad = JTextField()
self.buildpane()
self.lentext = 0
def show(self):
self.mainframe.pack()
self.mainframe.show()
def hide(self):
self.mainframe.hide()
def showGroupMessage(self, sender, text, metadata=None):
self.displayText(sender + ": " + text)
def setGroupMembers(self, members):
GroupConversation.setGroupMembers(self, members)
self.updatelist()
def setTopic(self, topic, author):
topictext = "Topic: " + topic + ", set by " + author
self.mainframe.setTitle(self.group.name + ": " + topictext)
self.displayText(topictext)
def memberJoined(self, member):
GroupConversation.memberJoined(self, member)
self.updatelist()
def memberChangedNick(self, oldnick, newnick):
GroupConversation.memberChangedNick(self, oldnick, newnick)
self.updatelist()
def memberLeft(self, member):
GroupConversation.memberLeft(self, member)
self.updatelist()
#GUI code
def buildpane(self):
buttons = JPanel(doublebuffered)
buttons.add(JButton("Hide", actionPerformed=self.hidewindow))
memberpane = JTable(self.memberdata)
memberframe = JScrollPane(memberpane)
chat = JPanel(doublebuffered)
chat.setLayout(BoxLayout(chat, BoxLayout.Y_AXIS))
chat.add(JScrollPane(self.display))
self.typepad.actionPerformed = self.send
chat.add(self.typepad)
chat.add(buttons)
mainpane = self.mainframe.getContentPane()
mainpane.setLayout(BoxLayout(mainpane, BoxLayout.X_AXIS))
mainpane.add(chat)
mainpane.add(memberframe)
def displayText(self, text):
self.lentext = self.lentext + len(text)
self.display.append(text)
self.display.setCaretPosition(self.lentext)
def updatelist(self):
self.memberdata.setDataVector([self.members], self.headers)
#actionListener
def send(self, ae):
text = self.typepad.getText()
self.typepad.setText("")
if text != "" and text != None:
GroupConversation.sendText(self, text)
def hidewindow(self, ae):
self.hide()
示例7: __init__
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
def __init__(self, parent, title, modal, app):
from javax.swing import JTextArea
border = BorderFactory.createEmptyBorder(5, 7, 7, 7)
self.getContentPane().setBorder(border)
self.setLayout(BoxLayout(self.getContentPane(), BoxLayout.Y_AXIS))
#Icon
icon = ImageIcon(File.separator.join([app.SCRIPTDIR,
"images",
"icons",
"logo.png"]))
iconLbl = JLabel(icon)
iconLbl.setAlignmentX(JLabel.CENTER_ALIGNMENT)
#Name
titleLbl = JLabel("Quality Assurance Tools script")
titleLbl.setAlignmentX(JLabel.CENTER_ALIGNMENT)
#Version
p = JPanel()
versionPanel = JPanel(GridLayout(2, 2))
versionPanel.add(JLabel("script: "))
versionPanel.add(JLabel(app.SCRIPTVERSION))
versionPanel.add(JLabel("tools: "))
self.toolsVersionLbl = JLabel(app.TOOLSVERSION)
versionPanel.add(self.toolsVersionLbl)
versionPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
p.add(versionPanel)
#Wiki
wikiLblPanel = JPanel(FlowLayout(FlowLayout.CENTER))
wikiLbl = UrlLabel(app.SCRIPTWEBSITE, "Wiki", 2)
wikiLblPanel.add(wikiLbl)
wikiLblPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT)
#Author, contributors and credits
creditsTextArea = JTextArea(15, 35, editable=False)
creditsTextArea.setBackground(None)
contribFile = open(File.separator.join([app.SCRIPTDIR, "CONTRIBUTORS"]), "r")
contribText = contribFile.read()
contribFile.close()
creditsTextArea.append(contribText)
creditsTextArea.setCaretPosition(0)
creditScrollPane = JScrollPane(creditsTextArea)
#OK button
okBtn = JButton("OK",
ImageProvider.get("ok"),
actionPerformed=self.on_okBtn_clicked)
okBtn.setAlignmentX(JButton.CENTER_ALIGNMENT)
#Layout
self.add(Box.createRigidArea(Dimension(0, 7)))
self.add(iconLbl)
self.add(Box.createRigidArea(Dimension(0, 7)))
self.add(titleLbl)
self.add(Box.createRigidArea(Dimension(0, 7)))
self.add(p)
self.add(wikiLblPanel)
self.add(Box.createRigidArea(Dimension(0, 7)))
self.add(creditScrollPane)
self.add(Box.createRigidArea(Dimension(0, 7)))
self.add(okBtn)
self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
self.pack()
示例8: JPanel
# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setCaretPosition [as 别名]
from jehep.ui import SetEnv
from jehep.ui import Editor
from javax.swing import JButton, JDialog, JLabel, JPanel, JScrollPane, JTextArea
from java.awt import BorderLayout
from java.awt import Color
from java.awt.event import ActionListener, KeyEvent, KeyListener, MouseListener
frame =JDialog();
topPanel = JPanel();
lowerPanel = JPanel();
jDescription = JTextArea(80, 100);
helpFile=SetEnv.DirPath+SetEnv.fSep+"Docs"+SetEnv.fSep+"HelpJythonShell.txt";
text=SetEnv.readFile(helpFile);
jDescription.setText(text);
jDescription.setCaretPosition(0);
# jDescription.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
jDescription.setEditable(0)
def exitme(event):
frame.dispose()
jB2 = JButton("Exit", actionPerformed=exitme)
lowerPanel.add(jB2);
topPanel.setLayout(BorderLayout());
# comments
jScrollPane1 = JScrollPane();