当前位置: 首页>>代码示例>>Python>>正文


Python JTextArea.setBackground方法代码示例

本文整理汇总了Python中javax.swing.JTextArea.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Python JTextArea.setBackground方法的具体用法?Python JTextArea.setBackground怎么用?Python JTextArea.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.setBackground方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Tip

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setBackground [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()
开发者ID:0x7678,项目名称:android-ssl-bypass,代码行数:43,代码来源:tip.py

示例2: appendText

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setBackground [as 别名]
	def appendText(self, message, user=None):
		'''This function takes care of appending any new messages to the content area
		'''
		message_label=JTextArea(message,2,3, font=self.label_2_font)
		#  If this is a message from the grab text function, create a new label, assign it's colours
		if user!=None:
			message_label.setBackground(Color(240,240,240))
			message_label.setForeground(Color(129,129,129))
		#  Otherwise set the format for receive function (no user passed in)	
		else:
			message_label.setBackground(Color(215,215,215))
			message_label.setForeground(Color(40,153,153))
		
		#  Format and style options for the new message labels	
		message_label.setEditable(False)
		message_label.setLineWrap(True)
		message_label.setWrapStyleWord(True)
		message_label.setBorder(BorderFactory.createLineBorder( Color(247,246,242),4))
		#  Sets the positioning of messages
		self.main_content.setCaretPosition(self.main_content.getDocument().getLength())
		doc = self.main_content.getStyledDocument()
		attr=SimpleAttributeSet()
		self.main_content.insertComponent(message_label)
		# Essential for jtextarea to be able to stack message
		doc.insertString( self.main_content.getDocument().getLength(),'\n ', attr)
		# Not sure if needed
		self.main_content.repaint()
		
		###  This is a late edit so it isn't included in the documentation. Basically trying to dynamically update the number
		###  of users label at runtime. Works for incrementing the value but not decrementing it.
		
		print(message)
		#  Only split the message if there are enough values to split (greeting messages differ in format to chat messages)
		try:
			user, text=message.split(' : ')
		except:
			return
			
		#print('Split values are %s %s'%(user, text))
		user=str(user.strip())
		#print(self.no_users)
		#print(user+' : '+text)
		#  If the user already in the list, pass
		if user in self.no_users:
			if text == ('User %s amach sa teach !'%user):
				self.no_users.remove(user)
				print('User % removed'%user)
			
		else:
			#print('User %s not in list'%user)
			if str(user) == 'You':
				#print('User is equal to "You"')
				return 
			self.no_users.append(user)
			print('User appended')
			self.number_users=len(self.no_users)
			#print('Length of user list is '+str(self.number_users))
	
		self.user_label2=JLabel(" Users online : %s "%str(len(self.no_users)),JLabel.RIGHT, font=self.label_2_font)
		#print('Label created')
		#print('Attempt to replace label')
		self.client_layout.replace(self.user_label, self.user_label2) 
		self.user_label = self.user_label2
		self.user_label.repaint()
		self.user_label.revalidate()
		print('Label updated')
开发者ID:k1nk33,项目名称:PyProject-Yr3,代码行数:68,代码来源:chat.py

示例3: __init__

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setBackground [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()
开发者ID:alex85k,项目名称:qat_script,代码行数:69,代码来源:AboutDialog.py

示例4: ChatClient

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setBackground [as 别名]
class ChatClient(JFrame):
	
	##  Constructor method, receives the variables from the ChatApp class as parameters
	
	def __init__(self, name, greeting, tn):
		'''Constructor, initialises base class & assigns variables
		'''
		# Call to the super method to take care of the base class(es)
		super(ChatClient, self).__init__()
		#  Assign the relevent variable names
		self.username=name
		self.greeting=greeting
		self.tn = tn
		self.no_users=[]
		#  Initiate the Threaded function for receiving messages
		t1=Thread(target=self.recvFunction)
		#  Set to daemon 
		t1.daemon=True
		t1.start()
		#Call the main UI
		uI=self.clientUI()
		
	##  Main GUI building function
	
	def clientUI(self):
		'''ClientUI and Widget creation
		'''
		#  Colours
		foreground_colour = Color(30,57,68)
		background_colour = Color(247,246,242)
		window_background = Color(145,190,210)
		#  Borders
		self.border2=BorderFactory.createLineBorder(foreground_colour,1, True)
		#  Fonts
		self.font= Font("Ubuntu Light",  Font.BOLD, 20)
		self.label_font= Font("Ubuntu Light",  Font.BOLD, 17)
		self.label_2_font= Font( "Ubuntu Light",Font.BOLD, 12)
		self.btn_font=Font("Ubuntu Light", Font.BOLD, 15)
		
		#  Set the layout parameters
		self.client_layout=GroupLayout(self.getContentPane())
		self.getContentPane().setLayout(self.client_layout)	
		self.getContentPane().setBackground(window_background)
		self.client_layout.setAutoCreateGaps(True)
		self.client_layout.setAutoCreateContainerGaps(True)
		self.setPreferredSize(Dimension(400, 450))
		
		#  Create widgets and assemble the GUI
		#  Main display area
		self.main_content=JTextPane()
		self.main_content.setBackground(background_colour)
		#self.main_content.setForeground(foreground_colour)
		self.main_content.setEditable(False)
		#  Message entry area  		
		self.message=JTextArea( 2,2, border=self.border2, font=self.label_font, keyPressed=self.returnKeyPress)
		self.message.requestFocusInWindow()	
		self.message.setBackground(background_colour)
		self.message.setForeground(foreground_colour)
		self.message.setLineWrap(True)
		self.message.setWrapStyleWord(True)
		self.message.setBorder(BorderFactory.createEmptyBorder(3,3,3,3))
		self.message.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), self.returnKeyPress) 
		#  BUttons
		quit_btn=JButton("Quit!", actionPerformed=ChatApp().closeEvent, border=self.border2, font=self.btn_font)
		go_btn=JButton("Send", actionPerformed=self.grabText, border=self.border2, font=self.btn_font)
		quit_btn.setBackground(background_colour)
		go_btn.setBackground(background_colour)
		quit_btn.setForeground(foreground_colour)
		go_btn.setForeground(foreground_colour)
		
		# Make scrollable
		self.scroll_content=JScrollPane(self.main_content)
		self.scroll_content.setPreferredSize(Dimension(150,275))
		self.scroll_content.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)
		self.scroll_content.setViewportView(self.main_content)
		self.scroll_content.setBackground(Color.WHITE)
		self.scroll_message=JScrollPane(self.message)
		self.scroll_message.setPreferredSize(Dimension(150,20))
		self.scroll_message.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS)
		
		# Test user label, still not updating after first round of messages
		self.user_label=JLabel(" Users online : %s "%(str(len(self.no_users))),JLabel.RIGHT, font=self.label_2_font)
		
		#  Assemble the components
		#  Horizontal layout
		self.client_layout.setHorizontalGroup(self.client_layout.createParallelGroup()
				.addComponent(self.scroll_content)
				.addGroup(self.client_layout.createParallelGroup(GroupLayout.Alignment.CENTER)
					.addComponent(self.scroll_message))
				.addGroup(self.client_layout.createSequentialGroup()
					.addComponent(quit_btn)
					.addComponent(go_btn).addGap(20))
				.addGroup(self.client_layout.createParallelGroup()
					.addComponent(self.user_label))
		)
		
		#  Vertical layout
		self.client_layout.setVerticalGroup(self.client_layout.createSequentialGroup()
			.addGroup(self.client_layout.createParallelGroup()
				.addComponent(self.scroll_content))
#.........这里部分代码省略.........
开发者ID:k1nk33,项目名称:PyProject-Yr3,代码行数:103,代码来源:chat.py

示例5: ConsolePanel

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import setBackground [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
#.........这里部分代码省略.........
开发者ID:doctorOb,项目名称:bashED,代码行数:103,代码来源:consolePanel.py


注:本文中的javax.swing.JTextArea.setBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。