本文整理汇总了Python中javax.swing.JLabel.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Python JLabel.setBackground方法的具体用法?Python JLabel.setBackground怎么用?Python JLabel.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.setBackground方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUI
# 需要导入模块: from javax.swing import JLabel [as 别名]
# 或者: from javax.swing.JLabel import setBackground [as 别名]
def initUI(self):
self.panel = JPanel(size=(50,50))
self.panel.setLayout(FlowLayout( ))
self.panel.setToolTipText("GPU Demo")
#TODO- change this so that it deletes itself when text is entered
self.textfield1 = JTextField('Smoothing Parameter',15)
self.panel.add(self.textfield1)
joclButton = JButton("JOCL",actionPerformed=self.onJocl)
joclButton.setBounds(100, 500, 100, 30)
joclButton.setToolTipText("JOCL Button")
self.panel.add(joclButton)
javaButton = JButton("Java",actionPerformed=self.onJava)
javaButton.setBounds(100, 500, 100, 30)
javaButton.setToolTipText("Java Button")
self.panel.add(javaButton)
qButton = JButton("Quit", actionPerformed=self.onQuit)
qButton.setBounds(200, 500, 80, 30)
qButton.setToolTipText("Quit Button")
self.panel.add(qButton)
newImage = ImageIO.read(io.File(getDataDir() + "input.png"))
resizedImage = newImage.getScaledInstance(600, 600,10)
newIcon = ImageIcon(resizedImage)
label1 = JLabel("Input Image",newIcon, JLabel.CENTER)
label1.setVerticalTextPosition(JLabel.TOP)
label1.setHorizontalTextPosition(JLabel.RIGHT)
label1.setSize(10,10)
label1.setBackground(Color.orange)
self.panel.add(label1)
self.getContentPane().add(self.panel)
self.clockLabel = JLabel()
self.clockLabel.setSize(1,1)
self.clockLabel.setBackground(Color.orange)
self.clockLabel.setVerticalTextPosition(JLabel.BOTTOM)
self.clockLabel.setHorizontalTextPosition(JLabel.LEFT)
myClockFont = Font("Serif", Font.PLAIN, 50)
self.clockLabel.setFont(myClockFont)
self.panel.add(self.clockLabel)
self.setTitle("Structure-oriented smoothing OpenCL Demo")
self.setSize(1200, 700)
self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
self.setLocationRelativeTo(None)
self.setVisible(True)
示例2: StatusPanel
# 需要导入模块: from javax.swing import JLabel [as 别名]
# 或者: from javax.swing.JLabel import setBackground [as 别名]
class StatusPanel(JPanel):
def __init__(self):
JPanel()
self.setLayout(GridLayout(1,1))
#self.add(JLabel('SELWB 1.0'))
self.statusLabel = JLabel('Idle', SwingConstants.CENTER)
self.statusLabel.setBackground(Color.GREEN)
self.statusLabel.setOpaque(True)
self.add(self.statusLabel)
def setStatus(self, str, bgColor = Color.GREEN):
self.statusLabel.setText(str)
self.statusLabel.setBackground(bgColor)
示例3: Demo
# 需要导入模块: from javax.swing import JLabel [as 别名]
# 或者: from javax.swing.JLabel import setBackground [as 别名]
class Demo(JFrame, Runnable):
def __init__(self):
super(Demo, self).__init__()
self.initUI()
def initUI(self):
self.panel = JPanel(size=(50,50))
self.panel.setLayout(FlowLayout( ))
self.panel.setToolTipText("GPU Demo")
#TODO- change this so that it deletes itself when text is entered
self.textfield1 = JTextField('Smoothing Parameter',15)
self.panel.add(self.textfield1)
joclButton = JButton("JOCL",actionPerformed=self.onJocl)
joclButton.setBounds(100, 500, 100, 30)
joclButton.setToolTipText("JOCL Button")
self.panel.add(joclButton)
javaButton = JButton("Java",actionPerformed=self.onJava)
javaButton.setBounds(100, 500, 100, 30)
javaButton.setToolTipText("Java Button")
self.panel.add(javaButton)
qButton = JButton("Quit", actionPerformed=self.onQuit)
qButton.setBounds(200, 500, 80, 30)
qButton.setToolTipText("Quit Button")
self.panel.add(qButton)
newImage = ImageIO.read(io.File(getDataDir() + "input.png"))
resizedImage = newImage.getScaledInstance(600, 600,10)
newIcon = ImageIcon(resizedImage)
label1 = JLabel("Input Image",newIcon, JLabel.CENTER)
label1.setVerticalTextPosition(JLabel.TOP)
label1.setHorizontalTextPosition(JLabel.RIGHT)
label1.setSize(10,10)
label1.setBackground(Color.orange)
self.panel.add(label1)
self.getContentPane().add(self.panel)
self.clockLabel = JLabel()
self.clockLabel.setSize(1,1)
self.clockLabel.setBackground(Color.orange)
self.clockLabel.setVerticalTextPosition(JLabel.BOTTOM)
self.clockLabel.setHorizontalTextPosition(JLabel.LEFT)
myClockFont = Font("Serif", Font.PLAIN, 50)
self.clockLabel.setFont(myClockFont)
self.panel.add(self.clockLabel)
self.setTitle("Structure-oriented smoothing OpenCL Demo")
self.setSize(1200, 700)
self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
self.setLocationRelativeTo(None)
self.setVisible(True)
def onQuit(self, e): System.exit(0)
def onJocl(self, e):
self.clockLabel.setText('running')
self.started = Calendar.getInstance().getTimeInMillis();
#print self.textfield1.getText()
#time.sleep(5)
iters = toInt(self.textfield1.getText())
jocl_smoother(iters)
elapsed = Calendar.getInstance().getTimeInMillis() - self.started;
self.clockLabel.setText( 'JOCL Elapsed: %.2f seconds' % ( float( elapsed ) / 1000.0 ) )
def onJava(self, e):
self.clockLabel.setText('running')
self.started = Calendar.getInstance().getTimeInMillis();
#print self.textfield1.getText()
#time.sleep(5)
iters = toInt(self.textfield1.getText())
java_smoother(iters)
elapsed = Calendar.getInstance().getTimeInMillis() - self.started;
self.clockLabel.setText( 'Java Elapsed: %.2f seconds' % ( float( elapsed ) / 1000.0 ) )
示例4: __init__
# 需要导入模块: from javax.swing import JLabel [as 别名]
# 或者: from javax.swing.JLabel import setBackground [as 别名]
class StackOverlay:
def __init__(self):
self.frame = None
self.overlayColorPreviewLabel = None
self.showStackOverlayWindow()
self.overlayColor = None
def onQuit(self, e):
print "Exiting..."
self.frame.dispose()
def showColorChooser(self, e):
colorChooser = JColorChooser()
self.overlayColor = colorChooser.showDialog(self.frame, "Choose color", Color.red)
self.overlayColorPreviewLabel.setBackground(self.overlayColor)
def showStackOverlayWindow(self):
all = JPanel()
all.setLayout(MigLayout())
self.imageIDs = WindowManager.getIDList()
self.imageNames = []
if self.imageIDs is None:
IJ.error("No open images", "Stack Overlay requires at least one image to be already open.")
return
for i in self.imageIDs:
self.imageNames.append(WindowManager.getImage(i).getTitle())
self.baseImageBox = JComboBox(self.imageNames)
baseImageBoxLabel = JLabel("Base image")
self.baseImageBox.setSelectedIndex(0)
all.add(baseImageBoxLabel)
all.add(self.baseImageBox, "wrap")
self.overlayImageBox = JComboBox(self.imageNames)
overlayImageBoxLabel = JLabel("Overlay image")
if len(self.imageNames) > 1:
self.overlayImageBox.setSelectedIndex(1)
all.add(overlayImageBoxLabel)
all.add(self.overlayImageBox, "wrap")
all.add(JSeparator(SwingConstants.HORIZONTAL), "span, wrap")
overlayStyleFrame = JPanel()
overlayStyleFrame.setLayout(MigLayout())
overlayStyleFrame.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Overlay Style"), BorderFactory.createEmptyBorder(5,5,5,5)))
colorLabel = JLabel("Overlay color")
self.overlayColorPreviewLabel = JLabel(" ")
self.overlayColorPreviewLabel.setBorder(BorderFactory.createEmptyBorder(0,0,1,0))
self.overlayColorPreviewLabel.setOpaque(True)
self.overlayColorPreviewLabel.setBackground(Color.red)
self.overlayColor = Color.red
colorPicker = JColorChooser()
colorPicker.setPreviewPanel(self.overlayColorPreviewLabel)
colorButton = JButton("Select color...", actionPerformed=self.showColorChooser)
opacityLabel = JLabel("Overlay opacity (%)")
opacitySpinnerModel = SpinnerNumberModel(100, 0, 100, 1)
self.opacitySpinner = JSpinner(opacitySpinnerModel)
overlayStyleFrame.add(colorLabel)
overlayStyleFrame.add(self.overlayColorPreviewLabel)
overlayStyleFrame.add(colorButton, "wrap")
overlayStyleFrame.add(opacityLabel)
overlayStyleFrame.add(self.opacitySpinner, "wrap")
all.add(overlayStyleFrame, "span, wrap")
self.virtualStackCheckbox = JCheckBox("Use Virtual Stack", True)
all.add(self.virtualStackCheckbox, "span, wrap")
# TODO: add non-thermonuclear cancel button functionality
overlayCancelButton = JButton("Cancel", actionPerformed=self.onQuit)
overlayStartButton = JButton("Overlay images", actionPerformed=self.overlayImages)
all.add(overlayCancelButton, "gapleft push")
all.add(overlayStartButton, "gapleft push")
self.frame = JFrame("Stack Overlay")
self.frame.getContentPane().add(JScrollPane(all))
self.frame.pack()
self.frame.setLocationRelativeTo(None)
self.frame.setVisible(True)
def overlayImages(self, e):
impBase = WindowManager.getImage(self.imageIDs[self.baseImageBox.getSelectedIndex()])
refBase = impBase.getStack().getProcessor(1)
impOverlay = WindowManager.getImage(self.imageIDs[self.overlayImageBox.getSelectedIndex()])
refOverlay = impOverlay.getStack().getProcessor(1)
print "Overlaying for stack sizes " + str(impBase.getStackSize()) + "/" + str(impOverlay.getStackSize()) + "..."
stack = None
#.........这里部分代码省略.........
示例5: getTableCellRendererComponent
# 需要导入模块: from javax.swing import JLabel [as 别名]
# 或者: from javax.swing.JLabel import setBackground [as 别名]
def getTableCellRendererComponent(
self, table, text, isSelected, hasFocus, row, column):
comp = JLabel(text)
comp.setOpaque(True) #MUST do this for background to show up.
comp.setBackground(self.color[row])
return comp