本文整理汇总了Python中javax.swing.JComboBox.setSelectedItem方法的典型用法代码示例。如果您正苦于以下问题:Python JComboBox.setSelectedItem方法的具体用法?Python JComboBox.setSelectedItem怎么用?Python JComboBox.setSelectedItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.setSelectedItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EditSymbolAttr
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
class EditSymbolAttr(JPanel):
def __init__(self, sattr):
self.attr = sattr
self.cbox = JColorChooser(self.attr.color)
self.sz_field = JTextField(str(self.attr.size))
szpanel = JPanel()
szpanel.add(self.sz_field)
szpanel.setBorder(BorderFactory.createTitledBorder("symbol size (integer)"))
self.filled_box = JCheckBox("Filled ?:",self.attr.filled)
self.shape_cbox = JComboBox(SymbolProps.sym_shape_map.keys())
self.shape_cbox.setSelectedItem(self.attr.shape)
self.shape_cbox.setBorder(BorderFactory.createTitledBorder("Shape"))
panel1 = JPanel()
panel1.setLayout(BorderLayout())
panel1.add(szpanel,BorderLayout.NORTH)
panel2 = JPanel()
panel2.setLayout(GridLayout(1,2))
panel2.add(self.shape_cbox)
panel2.add(self.filled_box)
panel1.add(panel2,BorderLayout.SOUTH)
self.setLayout(BorderLayout())
self.add(self.cbox,BorderLayout.CENTER)
self.add(panel1,BorderLayout.SOUTH)
def setAttribute(self,sattr):
self.attr = sattr
self.cbox.color = self.attr.color
self.sz_field.text = str(self.attr.size)
self.shape_cbox.setSelectedItem(self.attr.shape)
def update(self):
self.attr.color = self.cbox.getColor()
self.attr.size = string.atoi(self.sz_field.getText())
self.attr.filled = self.filled_box.isSelected()
self.attr.shape = self.shape_cbox.getSelectedItem()
self.attr.sym = self.attr.createSymbol()
示例2: build_combobox
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
def build_combobox(self, choices, default):
'''
Generic method to construct a combobox. choices should be an iterable
of strings of the choices to be made and default should be a string
which is equal to one of the values within the iterable.
'''
combo = JComboBox()
for choice in choices:
combo.addItem(choice)
combo.setSelectedItem(default)
return combo
示例3: build_servers_combobox
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
def build_servers_combobox(self):
combo = JComboBox()
# Go through list of servers and add to combo box.
for server in self.servers.keys():
if server != "default":
combo_item = "{}: {}:{}".format(server,
self.servers[server]['url'],
self.servers[server]['port'])
combo.addItem(combo_item)
# If this item is the default one, set it as selected
if server == self.servers['default']:
combo.setSelectedItem(combo_item)
return combo
示例4: EditCurveAttr
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
class EditCurveAttr(JPanel):
def __init__(self, cattr):
self.attr = cattr
self.cbox = JColorChooser(self.attr.color)
self.sym_panel = EditSymbolAttr(cattr.sym_prop)
self.thickness_field = JTextField(str(cattr.thickness),2)
self.draw_symbol_box = JCheckBox("Draw Symbol?",cattr.draw_symbol)
self.dps_field = JTextField(str(self.attr.data_per_symbol),2)
self.dash_box = JComboBox(CurveProps.DASH_TYPES.keys())
self.dash_box.setSelectedItem(self.attr.dash_type)
self.dash_box.setBorder(BorderFactory.createTitledBorder("Dash type: (Only JDK2 & Slow!)"))
tpanelx = JPanel()
tpanelx.add(self.thickness_field)
tpanelx.setBorder(BorderFactory.createTitledBorder("curve thickness (integer)"))
tpanely = JPanel()
tpanely.add(self.dps_field)
tpanely.setBorder(BorderFactory.createTitledBorder("data per symbol(integer)"))
tpanel = JPanel();tpanel.setLayout(GridLayout(2,2));
tpanel.add(self.draw_symbol_box); tpanel.add(tpanelx);
tpanel.add(tpanely); tpanel.add(self.dash_box);
panel1 = JPanel()
panel1.setLayout(BorderLayout())
panel1.add(self.cbox,BorderLayout.CENTER)
panel1.add(tpanel, BorderLayout.SOUTH)
panel2 = JPanel()
panel2.setLayout(BorderLayout())
panel2.add(self.sym_panel,BorderLayout.CENTER)
tp1 = JTabbedPane()
tp1.addTab("Curve Attributes",panel1)
tp1.addTab("Symbol Attributes",panel2)
tp1.setSelectedComponent(panel1)
self.setLayout(BorderLayout())
self.add(tp1,BorderLayout.CENTER)
def setAttribute(self,cattr):
self.attr = cattr
self.cbox.color = self.attr.color
self.sym_panel.setAttribute(cattr.sym_prop)
self.thickness_field.text = str(cattr.thickness)
self.dps_field.text = str(cattr.data_per_symbol)
self.draw_symbol_box.setSelected(cattr.draw_symbol)
self.dash_box.setSelectedItem(cattr.dash_type)
def update(self):
self.attr.color = self.cbox.getColor()
self.attr.thickness = string.atoi(self.thickness_field.text)
self.attr.data_per_symbol = string.atoi(self.dps_field.text)
self.attr.draw_symbol = self.draw_symbol_box.isSelected()
self.attr.dash_type = self.dash_box.getSelectedItem()
#print 'Updating Self.draw_symbol',self.draw_symbol,self.attr
self.sym_panel.update()
示例5: initParameterColumn
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
def initParameterColumn(self, table):
parameterTypes = JComboBox(sorted(PARAMETER_TYPES.keys()))
parameterTypes.setSelectedItem('PARAM_BODY')
parameterColumn = table.getColumnModel().getColumn(0)
parameterColumn.setCellEditor(DefaultCellEditor(parameterTypes))
whenTypes = JComboBox(['Before', 'After'])
whenTypes.setSelectedItem('Before')
whenColumn = table.getColumnModel().getColumn(2)
whenColumn.setCellEditor(DefaultCellEditor(whenTypes))
ruleTypes = JComboBox(sorted(RULES.keys()))
ruleColumn = table.getColumnModel().getColumn(3)
ruleColumn.setCellEditor(DefaultCellEditor(ruleTypes))
return
示例6: CurveDialog
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
class CurveDialog(JDialog):
def __init__(self, cattrs):
#JDialog.__init__(self,"Curve Attribute Editor")
#("Curve Attribute Editor")
if cattrs == None or len(cattrs) == 0:
raise "No curve attributes specified"
self.attrs = cattrs
self.cpanel = EditCurveAttr(cattrs[0])
pane = self.getContentPane()
pane.setLayout(BorderLayout())
x = map(lambda x: x+1,range(len(self.attrs)))
self.curveBox = JComboBox(x)
self.curveBox.setBorder(BorderFactory.createTitledBorder("Curve #"))
self.curveBox.setSelectedItem(0)
class CListener(ItemListener):
def __init__(self,cbox,cpanel,cattrs):
self.cbox = cbox
self.cpanel = cpanel
self.attrs = cattrs
def itemStateChanged(self, evt):
crvNo = self.cbox.getSelectedItem()
self.cpanel.update()
self.cpanel.setAttribute(self.attrs[crvNo-1])
self.curveBox.addItemListener(CListener(self.curveBox, self.cpanel,self.attrs))
okBtn = JButton("OK",actionPerformed=self.ok_action)
cancelBtn = JButton("Cancel",actionPerformed=self.cancel_action)
btnPanel = JPanel()
btnPanel.setLayout(GridLayout(1,3))
btnPanel.add(self.curveBox)
btnPanel.add(okBtn)
btnPanel.add(cancelBtn)
pane.add(self.cpanel,BorderLayout.CENTER)
pane.add(btnPanel, BorderLayout.SOUTH)
self.setLocation(100,100)
self.pack()
self.setVisible(1)
def ok_action(self,evt):
#crvNo = self.curveBox.getSelectedItem()
#print 'Setting attributes for ', crvNo
#print self.attrs[crvNo-1]
self.cpanel.update()
self.cancel_action(evt)
def cancel_action(self,evt):
self.dispose()
示例7: update_table
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
def update_table(self):
"""Updates the table with new data"""
columns = ["Type", "Action", "Name", "Value"]
data = []
for param in self._extender.sm.selected_session.params:
data.append(param.as_table_row())
data.append([Parameter.type_mapping[Parameter.PARAM_COOKIE], Parameter.ACTION_MODIFY, "", ""])
data_model = DefaultTableModel(data, columns, tableChanged=self.tableChanged)
self.modification_table.setModel(data_model)
# type combobox
type_combo = JComboBox(self._types)
type_column = self.modification_table.getColumnModel().getColumn(0)
type_column.setCellEditor(DefaultCellEditor(type_combo))
type_column.setMaxWidth(75)
# action combobox
action_combo = JComboBox(self._actions)
action_column = self.modification_table.getColumnModel().getColumn(1)
action_column.setCellEditor(DefaultCellEditor(action_combo))
action_column.setMaxWidth(75)
action_combo.setSelectedItem("replace")
示例8: NewAtfView
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
#.........这里部分代码省略.........
help_label,
18,
SpringLayout.NORTH,
panel)
layout.putConstraint(SpringLayout.EAST,
panel,
15,
SpringLayout.EAST,
help_label)
layout.putConstraint(SpringLayout.SOUTH,
panel,
10,
SpringLayout.SOUTH,
help_label)
# Add this to NewAtf JFrame
return panel
def build_language_row(self):
'''
Builds the language row.
'''
# Build own panel with SpringLayout.
panel = JPanel()
layout = SpringLayout()
panel.setLayout(layout)
# Get language list from settings.yaml, removing the default one from
# the list
languages = self.languages.keys()
languages.remove('default')
# Create necessary components and add them to panel.
language_label = JLabel('Language: ')
self.language_combo = JComboBox(languages)
# Set selected language to default
self.language_combo.setSelectedItem(self.languages['default'])
tooltip_text = "Choose a language from the dropdown menu."
help_label = self.build_help_label(tooltip_text)
panel.add(language_label)
panel.add(self.language_combo)
panel.add(help_label)
# Set up constraints to tell panel how to position components.
layout.putConstraint(SpringLayout.WEST,
language_label,
15,
SpringLayout.WEST,
panel)
layout.putConstraint(SpringLayout.NORTH,
language_label,
18,
SpringLayout.NORTH,
panel)
layout.putConstraint(SpringLayout.WEST,
self.language_combo,
90,
SpringLayout.WEST,
panel)
layout.putConstraint(SpringLayout.NORTH,
self.language_combo,
15,
SpringLayout.NORTH,
panel)
layout.putConstraint(SpringLayout.WEST,
help_label,
5,
SpringLayout.EAST,
self.language_combo)
layout.putConstraint(SpringLayout.NORTH,
示例9: QatDialog
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
#.........这里部分代码省略.........
def update_favourite_zone_indicator(self):
#icon
if self.app.favZone is not None:
self.favAreaIndicator.setIcon(self.app.favZone.icon)
#tooltip
messageArguments = array([self.app.favZone.name], String)
formatter = MessageFormat("")
formatter.applyPattern(self.app.strings.getString("favAreaIndicator_tooltip"))
msg = formatter.format(messageArguments)
self.favAreaIndicator.setToolTipText(msg)
#status
self.favAreaIndicator.setVisible(self.app.favouriteZoneStatus)
def set_checksTextFld_color(self, color):
"""Change color of textField under checksTable
"""
colors = {"white": (255, 255, 255),
"black": (0, 0, 0),
"green": (100, 200, 0),
"red": (200, 0, 0)}
if color == "default":
self.statsPanel.background = self.statsPanel_def_color
self.checksTextFld.foreground = colors["black"]
else:
self.statsPanel.background = colors[color]
self.checksTextFld.foreground = colors["white"]
def change_selection(self, source):
"""Change comboboxes and checks table selections after a
selection has been made by the user
"""
if source in ("menu", "layer", "add favourite"):
self.app.selectionChangedFromMenuOrLayer = True
self.toolsCombo.setSelectedItem(self.app.selectedTool)
self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel)
self.viewsCombo.setSelectedItem(self.app.selectedView.title)
self.checksTable.setModel(self.app.selectedTableModel)
self.refresh_checksTable_columns_geometries()
for i, c in enumerate(self.app.selectedView.checks):
if c == self.app.selectedChecks[0]:
break
self.checksTable.setRowSelectionInterval(i, i)
self.app.selectionChangedFromMenuOrLayer = False
else:
self.app.selectionChangedFromMenuOrLayer = False
if source == "toolsCombo":
self.viewsCombo.setModel(self.app.selectedTool.viewsComboModel)
self.viewsCombo.setSelectedIndex(0)
elif source == "viewsCombo":
self.checksTable.setModel(self.app.selectedTableModel)
self.refresh_checksTable_columns_geometries()
if self.app.selectedView.checks != []: # favourite checks may be none
self.checksTable.setRowSelectionInterval(0, 0)
def refresh_checksTable_columns_geometries(self):
self.checksTable.getColumnModel().getColumn(0).setCellRenderer(self.iconrenderer)
self.checksTable.getColumnModel().getColumn(0).setMaxWidth(25)
self.checksTable.getColumnModel().getColumn(2).setMaxWidth(60)
def activate_error_tab(self, status):
if status:
if self.tabbedPane.getTabCount() == 1:
self.tabbedPane.addTab(self.app.strings.getString("Fix"),
None,
self.panel2,
示例10: ConfigurableConfigPanel
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
#.........这里部分代码省略.........
return
self.params = getJSONfromUI()
self.saveButton.setEnabled(self.savedParams == None or not self.params.__str__() == self.savedParams)
def getJSONfromUI(self):
""" generated source for method getJSONfromUI """
newParams = JSONObject()
try:
if not self.name.getText().isEmpty():
newParams.put("name", self.name.getText())
newParams.put("strategy", self.strategy.getSelectedItem().__str__())
newParams.put("metagameStrategy", self.metagameStrategy.getSelectedItem().__str__())
newParams.put("stateMachine", self.stateMachine.getSelectedItem().__str__())
newParams.put("cacheStateMachine", self.cacheStateMachine.isSelected())
newParams.put("maxPlys", self.maxPlys.getModel().getValue())
newParams.put("heuristicFocus", self.heuristicFocus.getModel().getValue())
newParams.put("heuristicMobility", self.heuristicMobility.getModel().getValue())
newParams.put("heuristicOpponentFocus", self.heuristicOpponentFocus.getModel().getValue())
newParams.put("heuristicOpponentMobility", self.heuristicOpponentMobility.getModel().getValue())
newParams.put("mcDecayRate", self.mcDecayRate.getModel().getValue())
except JSONException as je:
je.printStackTrace()
return newParams
settingUI = False
def setUIfromJSON(self):
""" generated source for method setUIfromJSON """
self.settingUI = True
try:
if self.params.has("name"):
self.name.setText(self.params.getString("name"))
if self.params.has("strategy"):
self.strategy.setSelectedItem(self.params.getString("strategy"))
if self.params.has("metagameStrategy"):
self.metagameStrategy.setSelectedItem(self.params.getString("metagameStrategy"))
if self.params.has("stateMachine"):
self.stateMachine.setSelectedItem(self.params.getString("stateMachine"))
if self.params.has("cacheStateMachine"):
self.cacheStateMachine.setSelected(self.params.getBoolean("cacheStateMachine"))
if self.params.has("maxPlys"):
self.maxPlys.getModel().setValue(self.params.getInt("maxPlys"))
if self.params.has("heuristicFocus"):
self.heuristicFocus.getModel().setValue(self.params.getInt("heuristicFocus"))
if self.params.has("heuristicMobility"):
self.heuristicMobility.getModel().setValue(self.params.getInt("heuristicMobility"))
if self.params.has("heuristicOpponentFocus"):
self.heuristicOpponentFocus.getModel().setValue(self.params.getInt("heuristicOpponentFocus"))
if self.params.has("heuristicOpponentMobility"):
self.heuristicOpponentMobility.getModel().setValue(self.params.getInt("heuristicOpponentMobility"))
if self.params.has("mcDecayRate"):
self.mcDecayRate.getModel().setValue(self.params.getInt("mcDecayRate"))
except JSONException as je:
je.printStackTrace()
finally:
self.settingUI = False
def loadParamsJSON(self, fromFile):
""" generated source for method loadParamsJSON """
if not fromFile.exists():
return
self.associatedFile = fromFile
self.associatedFileField.setText(self.associatedFile.getPath())
self.params = JSONObject()
try:
try:
示例11: __init__
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
class NewAccountGUI:
def __init__(self, amgui):
self.amgui = amgui
self.am = amgui.acctmanager
self.buildgwinfo()
self.autologin = JCheckBox("Automatically Log In")
self.acctname = JTextField()
self.gwoptions = JPanel(doublebuffered)
self.gwoptions.border = TitledBorder("Gateway Options")
self.buildgwoptions("Twisted")
self.mainframe = JFrame("New Account Window")
self.buildpane()
def buildgwinfo(self):
self.gateways = {
"Twisted": {
"ident": JTextField(),
"passwd": JPasswordField(),
"host": JTextField("twistedmatrix.com"),
"port": JTextField("8787"),
"service": JTextField("twisted.words"),
"persp": JTextField(),
},
"AIM": {
"ident": JTextField(),
"passwd": JPasswordField(),
"host": JTextField("toc.oscar.aol.com"),
"port": JTextField("9898"),
},
"IRC": {
"ident": JTextField(),
"passwd": JPasswordField(),
"host": JTextField(),
"port": JTextField("6667"),
"channels": JTextField(),
},
}
self.displayorder = {
"Twisted": [
["Identity Name", "ident"],
["Password", "passwd"],
["Host", "host"],
["Port", "port"],
["Service Name", "service"],
["Perspective Name", "persp"],
],
"AIM": [["Screen Name", "ident"], ["Password", "passwd"], ["Host", "host"], ["Port", "port"]],
"IRC": [
["Nickname", "ident"],
["Password", "passwd"],
["Host", "host"],
["Port", "port"],
["Channels", "channels"],
],
}
def buildgwoptions(self, gw):
self.gwoptions.removeAll()
self.gwoptions.layout = GridLayout(len(self.gateways[gw]), 2)
for mapping in self.displayorder[gw]:
self.gwoptions.add(JLabel(mapping[0]))
self.gwoptions.add(self.gateways[gw][mapping[1]])
def buildpane(self):
gw = JPanel(GridLayout(1, 2), doublebuffered)
gw.add(JLabel("Gateway"))
self.gwlist = JComboBox(self.gateways.keys()) # , actionPerformed=self.changegw)
self.gwlist.setSelectedItem("Twisted")
gw.add(self.gwlist)
stdoptions = JPanel(GridLayout(2, 2), doublebuffered)
stdoptions.border = TitledBorder("Standard Options")
stdoptions.add(JLabel())
stdoptions.add(self.autologin)
stdoptions.add(JLabel("Account Name"))
stdoptions.add(self.acctname)
buttons = JPanel(FlowLayout(), doublebuffered)
buttons.add(JButton("OK", actionPerformed=self.addaccount))
buttons.add(JButton("Cancel", actionPerformed=self.cancel))
mainpane = self.mainframe.getContentPane()
mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS)
mainpane.add(gw)
mainpane.add(self.gwoptions)
mainpane.add(stdoptions)
mainpane.add(buttons)
def show(self):
self.mainframe.setLocation(100, 100)
self.mainframe.pack()
self.mainframe.show()
# actionlisteners
def changegw(self, ae):
self.buildgwoptions(self.gwlist.getSelectedItem())
self.mainframe.pack()
self.mainframe.show()
def addaccount(self, ae):
#.........这里部分代码省略.........
示例12: BurpExtender
# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import setSelectedItem [as 别名]
#.........这里部分代码省略.........
chooseProjPathButton.setBounds(470, 90, 100, 30)
importProjButton = JButton("Import",actionPerformed=self.importProj)
importProjButton.setBounds(470, 10, 100, 30)
exportProjButton = JButton("Export",actionPerformed=self.exportProj)
exportProjButton.setBounds(575, 10, 100, 30)
openProjButton = JButton("Open Directory",actionPerformed=self.openProj)
openProjButton.setBounds(680, 10, 130, 30)
currentProjectLabel = JLabel("Current:")
currentProjectLabel.setBounds(10, 10, 140, 30)
projects = self.config.options('projects')
self.currentProject = JComboBox(projects)
self.currentProject.addActionListener(projectChangeHandler(self))
self.currentProject.setBounds(140, 10, 140, 30)
self.autoSave = JCheckBox("Auto Save Mode")
self.autoSave.setEnabled(False) # implement this feature
self.autoSave.setBounds(300, 10, 140, 30)
self.autoSave.setToolTipText("Will save any changed value while focus is out")
addProjButton = JButton("Add / Update",actionPerformed=self.addProj)
addProjButton.setBounds(10, 330, 150, 30)
removeProjButton = JButton("Remove Current",actionPerformed=self.rmProj)
removeProjButton.setBounds(315, 330, 146, 30)
generalOptions = self.config.options('general')
if 'default project' in generalOptions:
defaultProj = self.config.get('general','default project')
self.currentProject.getModel().setSelectedItem(defaultProj)
self.projPath.setText(self.config.get('projects',self.currentProject.getSelectedItem()))
self.clearProjTab = True
self.projectSettings = JPanel()
self.projectSettings.setBounds(0, 0, 1000, 1000)
self.projectSettings.setLayout(None)
self.projectSettings.add(reportLabel)
self.projectSettings.add(detailsLabel)
self.projectSettings.add(projPathLabel)
self.projectSettings.add(addProjButton)
self.projectSettings.add(openProjButton)
self.projectSettings.add(projNameLabel)
self.projectSettings.add(projDetailsScroll)
self.projectSettings.add(importProjButton)
self.projectSettings.add(exportProjButton)
self.projectSettings.add(removeProjButton)
self.projectSettings.add(generateReportButton)
self.projectSettings.add(chooseProjPathButton)
self.projectSettings.add(currentProjectLabel)
self.projectSettings.add(self.projPath)
self.projectSettings.add(self.autoSave)
self.projectSettings.add(self.projName)
self.projectSettings.add(self.reportType)
self.projectSettings.add(self.currentProject)
def initTabs(self):
#
## init autorize tabs
#
self._splitpane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT)
self.scrollPane = JScrollPane(self.logTable)