本文整理汇总了Python中javax.swing.JButton.setForeground方法的典型用法代码示例。如果您正苦于以下问题:Python JButton.setForeground方法的具体用法?Python JButton.setForeground怎么用?Python JButton.setForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JButton
的用法示例。
在下文中一共展示了JButton.setForeground方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUI
# 需要导入模块: from javax.swing import JButton [as 别名]
# 或者: from javax.swing.JButton import setForeground [as 别名]
def initUI(self):
'''Initial UI and Widget creation takes place here!
'''
self.setContentPane = JPanel()
#self.setDefaultLookAndFeelDecorated(True)
# Borders
foreground_colour = Color(30,57,68)
background_colour = Color(247,246,242)
window_background = Color(145,190,210)
self.border = BorderFactory.createLoweredBevelBorder()
self.border2 = BorderFactory.createLineBorder(foreground_colour, 1, True)
# Fonts
self.entry_font= Font("Ubuntu Light", Font.BOLD, 20)
self.label_font= Font("Ubuntu Light", Font.BOLD, 17)
self.btn_font=Font("Ubuntu Light", Font.BOLD, 15)
# Layout start
layout=GroupLayout(self.getContentPane())
self.getContentPane().setLayout(layout)
layout.setAutoCreateGaps(True)
layout.setAutoCreateContainerGaps(True)
self.setPreferredSize(Dimension(300, 150))
# Create the labels
user_label= JLabel(" Username : ",JLabel.LEFT, font=self.label_font)
server_label=JLabel(" Server : ", JLabel.LEFT, font=self.label_font)
# Colours
user_label.setForeground(foreground_colour)
server_label.setForeground(foreground_colour)
# Create the text entries
self.username=JTextField(actionPerformed=self.continueEvent, border=self.border2, font = self.entry_font)
self.server=JTextField(actionPerformed=self.continueEvent, border=self.border2, font = self.entry_font)
# Colours
self.username.setBackground(background_colour)
self.server.setBackground(background_colour)
self.username.setForeground(foreground_colour)
self.server.setForeground(foreground_colour)
# Allow editable
self.username.setEditable(True)
self.server.setEditable(True)
# Create the buttons
quit_btn=JButton(" Quit! ", actionPerformed=self.closeEvent, border=self.border2, font=self.btn_font)
go_btn=JButton(" Go! ", actionPerformed=self.continueEvent, border=self.border2, font=self.btn_font)
# Colours
quit_btn.setBackground(background_colour)
go_btn.setBackground(background_colour)
quit_btn.setForeground(foreground_colour)
go_btn.setForeground(foreground_colour)
# Setting up the horizontal groups parameters
layout.setHorizontalGroup(layout.createSequentialGroup()
# Left side
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(user_label)
.addComponent(server_label))
# Right side
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(self.username)
.addComponent(self.server)
.addGroup(layout.createSequentialGroup()
.addComponent(quit_btn)
.addComponent(go_btn)))
)
# Setting up Vertical Groups
layout.setVerticalGroup(layout.createSequentialGroup()
# Top group
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(user_label)
.addComponent(self.username))
# Middle group
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(server_label)
.addComponent(self.server))
# Bottom group
.addGroup(layout.createParallelGroup()
.addComponent(quit_btn)
.addComponent(go_btn))
)
# Finalise the GUI
layout.linkSize(SwingConstants.HORIZONTAL, [quit_btn,go_btn])
self.getContentPane().setBackground(window_background)
self.pack()
self.setTitle('Chat Login')
self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
self.setLocationRelativeTo(None)
self.setVisible(True)
示例2: ButtonPanel
# 需要导入模块: from javax.swing import JButton [as 别名]
# 或者: from javax.swing.JButton import setForeground [as 别名]
class ButtonPanel(Panel):
playButton = None
helpButton = None
resetButton = None
exitButton = None
def __init__(self, inconsolePanel,dialogPanel):
self.consolePanel = inconsolePanel
self.dialogPanel = dialogPanel
Panel.__init__(self, "gap 1px 1px, insets 0 0 0 0, flowy")
def initUI(self):
self.setBackground(Color(0, 50, 0))
self.playButtonS = ImageIcon('bin/gui/media/' + "playButton.png")
self.helpButtonS = ImageIcon('bin/gui/media/' + "helpButton.png")
self.resetButtonS = ImageIcon('bin/gui/media/' + "resetButton.png")
self.exitButtonS = ImageIcon('bin/gui/media/' + "exitButton.png")
self.playButtonU = ImageIcon('bin/gui/media/' + "playButton_unselected.png")
self.helpButtonU = ImageIcon('bin/gui/media/' + "helpButton_unselected.png")
self.resetButtonU = ImageIcon('bin/gui/media/' + "resetButton_unselected.png")
self.exitButtonU = ImageIcon('bin/gui/media/' + "exitButton_unselected.png")
class MouseHoverAdap(MouseAdapter):
def __init__(self, butt, entImage, leaImage):
self.entImage = entImage
self.leaImage = leaImage
self.butt = butt
self.butt.setIcon(self.leaImage)
def mouseEntered(self, m):
self.butt.setIcon(self.entImage)
#self.butt.repaint()
def mouseExited(self, m):
self.butt.setIcon(self.leaImage)
#self.butt.repaint()
self.playButton = JButton(self.playButtonS)
self.playButton.setForeground(Color(0, 245, 0))
#self.playButton.setPreferredSize(Dimension(playButton.getIconWidth(), playButton.getIconHeight()))
#self.playButton.setBackground(Color(125, 125, 25))
self.playButton.setMaximumSize(Dimension(self.playButtonS.getIconWidth(), self.playButtonS.getIconHeight()))
self.playButton.setContentAreaFilled(False)
self.helpButton = JButton(self.helpButtonS)
self.helpButton.setForeground(Color(0, 235, 0))
self.helpButton.setMaximumSize(Dimension(self.helpButtonS.getIconWidth(), self.helpButtonS.getIconHeight()))
self.helpButton.setContentAreaFilled(False)
self.resetButton = JButton(self.resetButtonS)
self.resetButton.setForeground(Color(0, 225, 0))
self.resetButton.setMaximumSize(Dimension(self.resetButtonS.getIconWidth(), self.resetButtonS.getIconHeight()))
self.resetButton.setContentAreaFilled(False)
self.exitButton = JButton(self.exitButtonS)
self.exitButton.setForeground(Color(0, 215, 0))
self.exitButton.setContentAreaFilled(False)
self.exitButton.setMaximumSize(Dimension(self.exitButtonS.getIconWidth(), self.exitButtonS.getIconHeight()))
# self.playButton.addMouseListener(MouseHoverAdap(self.playButton, self.playButtonS, self.playButtonU))
# self.helpButton.addMouseListener(MouseHoverAdap(self.helpButton, self.helpButtonS, self.helpButtonU))
# self.resetButton.addMouseListener(MouseHoverAdap(self.resetButton, self.resetButtonS, self.resetButtonU))
# self.exitButton.addMouseListener(MouseHoverAdap(self.exitButton, self.exitButtonS, self.exitButtonU))
class PlayButtonActionListener(ActionListener):
def actionPerformed(button, e):
self.dialogPanel.speak(self.consolePanel.console.do_play(''))
self.playButton.addActionListener(PlayButtonActionListener())
class HelpBUttonActionListener(ActionListener):
def actionPerformed(button, e):
self.dialogPanel.speak(self.consolePanel.console.do_hint(''))
self.helpButton.addActionListener(HelpBUttonActionListener())
class ResetButtonActionListener(ActionListener):
def actionPerformed(button, e):
self.dialogPanel.speak(self.consolePanel.console.do_reset(''))
self.resetButton.addActionListener(ResetButtonActionListener())
class ExitButtonActionListener(ActionListener):
def actionPerformed(button, e):
System.exit(0)
self.exitButton.addActionListener(ExitButtonActionListener())
def addUI(self):
self.add(self.playButton, "push, grow")
self.add(self.helpButton, "push, grow")
self.add(self.resetButton, "push, grow")
self.add(self.exitButton, "push, grow")
示例3: clientUI
# 需要导入模块: from javax.swing import JButton [as 别名]
# 或者: from javax.swing.JButton import setForeground [as 别名]
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))
.addComponent(self.scroll_message)
.addGroup(self.client_layout.createParallelGroup()
.addComponent(quit_btn)
.addComponent(go_btn))
.addGroup(self.client_layout.createParallelGroup()
.addComponent(self.user_label))
)
# Finalise the GUI
self.client_layout.linkSize(SwingConstants.HORIZONTAL, [quit_btn,go_btn, self.user_label])
self.pack()
self.message.requestFocusInWindow()
self.setTitle(">>> Client %s <<<"%self.username)
self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
self.setLocationRelativeTo(None)
self.setVisible(True)
# Display the server greeting
self.appendText('\n'+self.greeting+'\n')