本文整理汇总了Python中javax.swing.JTable.getSelectedRow方法的典型用法代码示例。如果您正苦于以下问题:Python JTable.getSelectedRow方法的具体用法?Python JTable.getSelectedRow怎么用?Python JTable.getSelectedRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getSelectedRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from javax.swing import JTable [as 别名]
# 或者: from javax.swing.JTable import getSelectedRow [as 别名]
class AccountManagementGUI:
def __init__(self):
self.acctmanager = AccountManager()
self.mainframe = JFrame("Account Manager")
self.chatui = None
self.headers = ["Account Name", "Status", "Autologin", "Gateway"]
self.data = UneditableTableModel([], self.headers)
self.table = JTable(self.data)
self.table.columnSelectionAllowed = 0 # cannot select columns
self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION
self.connectbutton = JButton("Connect", actionPerformed=self.connect)
self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect)
self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount)
self.buildpane()
self.mainframe.pack()
self.mainframe.show()
def buildpane(self):
buttons = JPanel(FlowLayout(), doublebuffered)
buttons.add(self.connectbutton)
buttons.add(self.dconnbutton)
buttons.add(JButton("New", actionPerformed=self.addNewAccount))
buttons.add(self.deletebutton)
buttons.add(JButton("Quit", actionPerformed=self.quit))
mainpane = self.mainframe.getContentPane()
mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS)
mainpane.add(JScrollPane(self.table))
mainpane.add(buttons)
self.update()
def update(self):
self.data.setDataVector(self.acctmanager.getSnapShot(), self.headers)
if self.acctmanager.isEmpty():
self.deletebutton.setEnabled(0)
self.connectbutton.setEnabled(0)
self.dconnbutton.setEnabled(0)
else:
self.deletebutton.setEnabled(1)
if not 1 in self.acctmanager.getConnectionInfo(): # all disconnected
self.dconnbutton.setEnabled(0)
self.connectbutton.setEnabled(1)
elif not 0 in self.acctmanager.getConnectionInfo(): # all connected
self.dconnbutton.setEnabled(1)
self.connectbutton.setEnabled(0)
else:
self.dconnbutton.setEnabled(1)
self.connectbutton.setEnabled(1)
# callable button actions
def connect(self, ae):
print "Trying to connect"
row = self.table.getSelectedRow()
if row < 0:
print "Trying to connect to an account but no account selected"
else:
acctname = self.data.getValueAt(row, 0)
if not self.chatui:
self.chatui = twisted.words.im.jychat.JyChatUI()
self.acctmanager.connect(acctname, self.chatui)
self.update()
def disconnect(self, ae):
print "Trying to disconnect"
row = self.table.getSelectedRow()
if row < 0:
print "Trying to logoff an account but no account was selected."
else:
acctname = self.data.getValueAt(row, 0)
self.acctmanager.disconnect(acctname)
self.update()
def addNewAccount(self, ae):
print "Starting new account creation"
NewAccountGUI(self).show()
def deleteAccount(self, ae):
print "Deleting account"
row = self.table.getSelectedRow()
if row < 0:
print "Trying to delete an account but no account selected"
else:
acctname = self.data.getValueAt(row, 0)
self.acctmanager.delAccount(acctname)
self.update()
def quit(self, ae):
self.acctmanager.quit()
sys.exit()
示例2: BurpExtender
# 需要导入模块: from javax.swing import JTable [as 别名]
# 或者: from javax.swing.JTable import getSelectedRow [as 别名]
class BurpExtender(IBurpExtender,ITab,IHttpListener):
def registerExtenderCallbacks(self,callbacks):
self.callbacks = callbacks
self.helpers = callbacks.getHelpers()
self.callbacks.setExtensionName("KkMultiProxy")
self.PROXY_LIST = []
self.jPanel = JPanel()
boxVertical = Box.createVerticalBox()
boxHorizontal = Box.createHorizontalBox()
boxHorizontal.add(JButton("File",actionPerformed=self.getFile))
self.FileText = JTextField("")
boxHorizontal.add(self.FileText)
boxVertical.add(boxHorizontal)
TableHeader = ('IP','PORT')
TableModel = DefaultTableModel(self.PROXY_LIST,TableHeader)
self.Table = JTable(TableModel)
boxVertical.add(self.Table)
boxHorizontal = Box.createHorizontalBox()
boxHorizontal.add(JButton("Add",actionPerformed=self.addIP))
boxHorizontal.add(JButton("Delete",actionPerformed=self.deleteIP))
boxHorizontal.add(JButton("Save",actionPerformed=self.saveIP))
boxVertical.add(boxHorizontal)
self.jPanel.add(boxVertical)
self.callbacks.addSuiteTab(self)
self.callbacks.registerHttpListener(self)
return
def getFile(self,button):
dlg = JFileChooser()
result = dlg.showOpenDialog(None)
if result == JFileChooser.APPROVE_OPTION:
f = dlg.getSelectedFile()
path = f.getPath()
self.FileText.setText(path)
try:
self.getIPList(path)
except:
exit(0)
def addIP(self,button):
#chooser = JFileChooser()
#chooser.showOpenDialog(None)
demo = DialogDemo(self.Table)
def deleteIP(self,button):
selectRows = len(self.Table.getSelectedRows())
TableModel = self.Table.getModel()
if selectRows:
selectedRowIndex = self.Table.getSelectedRow()
TableModel.removeRow(selectedRowIndex)
def saveIP(self,button):
TableModel = self.Table.getModel()
rowCount = TableModel.getRowCount()
result_str = ""
for i in range(rowCount):
if i == 0:
result_str+=TableModel.getValueAt(i,0)+':'+TableModel.getValueAt(i,1)
else:
result_str+='|'+TableModel.getValueAt(i,0)+':'+TableModel.getValueAt(i,1)
print result_str
f = open(self.FileText.getText(),'w+')
f.write(result_str)
f.close()
def getTabCaption(self):
return "MultiProxy"
def getUiComponent(self):
return self.jPanel
def processHttpMessage(self,toolFlag,messageIsRequest,messageInfo):
if messageIsRequest:
httpService = messageInfo.getHttpService()
print httpService.getHost()
# if the host is HOST_FROM, change it to HOST_TO
i = randint(0,len(self.TableDatas)-1)
messageInfo.setHttpService(self.helpers.buildHttpService(self.PROXY_LIST[i]['ip'], self.PROXY_LIST[i]['port'], httpService.getProtocol()))
print messageInfo.getHttpService().getHost()
def getIPList(self,path):
f = open(path,'r+')
content = f.read()
f.close()
if content:
ip_array = content.split('|')
for _ip in ip_array:
ip = _ip.split(':')[0]
port = _ip.split(':')[1]
self.PROXY_LIST.append([ip,port])
print self.PROXY_LIST
示例3: ContactsListGUI
# 需要导入模块: from javax.swing import JTable [as 别名]
# 或者: from javax.swing.JTable import getSelectedRow [as 别名]
class ContactsListGUI(ContactsList):
"""A GUI object that displays a contacts list"""
def __init__(self, chatui):
ContactsList.__init__(self, chatui)
self.clientsByName = {}
self.mainframe = JFrame("Contacts List")
self.headers = ["Contact", "Status", "Idle", "Account"]
self.data = UneditableTableModel([], self.headers)
self.table = JTable(self.data,
columnSelectionAllowed = 0, #cannot select columns
selectionMode = ListSelectionModel.SINGLE_SELECTION)
self.buildpane()
self.mainframe.pack()
self.mainframe.show()
def setContactStatus(self, person):
ContactsList.setContactStatus(self, person)
self.update()
def registerAccountClient(self, client):
ContactsList.registerAccountClient(self, client)
if not client.accountName in self.clientsByName.keys():
self.clientsByName[client.accountName] = client
def unregisterAccount(self, client):
ContactsList.unregisterAccountClient(self, client)
if client.accountName in self.clientsByName.keys():
del self.clientsByName[client.accountName]
def contactChangedNick(self, person, newnick):
ContactsList.contactChangedNick(self, person, newnick)
self.update()
#GUI code
def buildpane(self):
buttons = JPanel(FlowLayout(), doublebuffered)
buttons.add(JButton("Send Message", actionPerformed=self.message))
buttons.add(JButton("Add Contact", actionPerformed=self.addContact))
#buttons.add(JButton("Quit", actionPerformed=self.quit))
mainpane = self.mainframe.getContentPane()
mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS))
mainpane.add(JScrollPane(self.table))
mainpane.add(buttons)
self.update()
def update(self):
contactdata = []
for contact in self.onlineContacts.values():
if contact.status == AWAY:
stat = "(away)"
else:
stat = "(active)"
contactdata.append([contact.name, stat, contact.getIdleTime(),
contact.client.accountName])
self.data.setDataVector(contactdata, self.headers)
#callable actionlisteners
def message(self, ae):
row = self.table.getSelectedRow()
if row < 0:
print "Trying to send IM to person, but no person selected"
else:
person = self.onlineContacts[self.data.getValueAt(row, 0)]
self.chat.getConversation(person)
def addContact(self, ae):
_AccountAdder(self)
def quit(self, ae):
sys.exit()