「Jython JTable 1」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==Jython JTable 1== [Jython Swing][Swing][Jython][Python] ===方針=== 以下を参考に、Jythonでテーブルを実装してみる *http://java.sun.com/docs/boo…」) |
|||
(同じ利用者による、間の3版が非表示) | |||
1行目: | 1行目: | ||
− | ==Jython JTable 1== | + | ==[[Jython JTable 1]]== |
− | [Jython Swing][Swing][Jython][Python] | + | [[Jython Swing]] | [[Swing]] | [[Jython]] | [[Python]] | |
===方針=== | ===方針=== | ||
− | + | 以下を参考に、[[Jython]]でテーブルを実装してみる | |
*http://java.sun.com/docs/books/tutorial/uiswing/components/table.html | *http://java.sun.com/docs/books/tutorial/uiswing/components/table.html | ||
*http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple | *http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple | ||
16行目: | 16行目: | ||
from java.lang import * | from java.lang import * | ||
− | from javax.swing import JFrame; | + | from javax.swing import [[JFrame]]; |
from javax.swing import JPanel; | from javax.swing import JPanel; | ||
from javax.swing import JScrollPane; | from javax.swing import JScrollPane; | ||
from javax.swing import JTable; | from javax.swing import JTable; | ||
− | from javax.swing import | + | from javax.swing import [[Swing]]Utilities |
from javax.swing.table import TableModel | from javax.swing.table import TableModel | ||
from javax.swing import UIManager | from javax.swing import UIManager | ||
59行目: | 59行目: | ||
def createUI(self): | def createUI(self): | ||
− | frame = JFrame("SimpleTableDemo") | + | frame = [[JFrame]]("SimpleTableDemo") |
− | frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE | + | frame.defaultCloseOperation = [[JFrame]].EXIT_ON_CLOSE |
self.opaque = True | self.opaque = True | ||
66行目: | 66行目: | ||
frame.pack() | frame.pack() | ||
− | frame. | + | frame.[[vi]]sible = True |
class MouseListener(MouseAdapter): | class MouseListener(MouseAdapter): | ||
73行目: | 73行目: | ||
def mouseClicked(self, e): | def mouseClicked(self, e): | ||
− | + | num[[R]]ows = self.table.rowCount | |
numCols = self.table.columnCount | numCols = self.table.columnCount | ||
model = self.table.model | model = self.table.model | ||
print "Value of data: " | print "Value of data: " | ||
− | for i in range( | + | for i in range(num[[R]]ows): |
print "\t\trow %d:" % i, | print "\t\trow %d:" % i, | ||
for j in range(numCols): | for j in range(numCols): | ||
85行目: | 85行目: | ||
print "-" * 25 | print "-" * 25 | ||
− | class Invoker( | + | class Invoker([[R]]unnable): |
def run(self): | def run(self): | ||
− | # Java Look & Feel (Metal) のデフォルトでボールドフォントを使用しない | + | # [[Java]] Look & Feel (Metal) のデフォルトでボールドフォントを使用しない |
UIManager.put("swing.boldMetal", Boolean.FALSE) | UIManager.put("swing.boldMetal", Boolean.FALSE) | ||
sample = JTableTest() | sample = JTableTest() | ||
sample.createUI() | sample.createUI() | ||
− | + | [[Swing]]Utilities.invokeLater(Invoker()) |
2020年2月16日 (日) 04:28時点における最新版
Jython JTable 1
Jython Swing | Swing | Jython | Python |
方針
以下を参考に、Jythonでテーブルを実装してみる
- http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
- http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple
ソースコード
実行例
ソースコード
# -*- coding: utf-8 -*- from java.lang import * from javax.swing import JFrame; from javax.swing import JPanel; from javax.swing import JScrollPane; from javax.swing import JTable; from javax.swing import SwingUtilities from javax.swing.table import TableModel from javax.swing import UIManager from java.awt import Dimension; from java.awt import GridLayout; from java.awt.event import MouseAdapter; from java.awt.event import MouseEvent; class JTableTest(JPanel): def __init__(self): self.DEBUG = True super(JTableTest,self).__init__(GridLayout(1,0)) columnNames = [ "First Name", "Last Name", "Sport", "# of Years", "Vegetarian"] data = [ ["Mary", "Campione","Snowboarding", 5, False], ["Alison", "Huml","Rowing", 3, True], ["Kathy", "Walrath","Knitting", 2, False], ["Sharon", "Zakhour","Speed reading", 20, True], ["Philip", "Milne","Pool", 10, False] ] table = JTable(data, columnNames) table.preferredScrollableViewportSize = Dimension(500, 70) table.fillsViewportHeight = True if self.DEBUG: table.addMouseListener(MouseListener(table)) scrollPane = JScrollPane(table) self.add(scrollPane) def createUI(self): frame = JFrame("SimpleTableDemo") frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE self.opaque = True frame.contentPane = self frame.pack() frame.visible = True class MouseListener(MouseAdapter): def __init__(self, table): self.table = table def mouseClicked(self, e): numRows = self.table.rowCount numCols = self.table.columnCount model = self.table.model print "Value of data: " for i in range(numRows): print "\t\trow %d:" % i, for j in range(numCols): print "\t%s" % model.getValueAt(i, j), print "" print "-" * 25 class Invoker(Runnable): def run(self): # Java Look & Feel (Metal) のデフォルトでボールドフォントを使用しない UIManager.put("swing.boldMetal", Boolean.FALSE) sample = JTableTest() sample.createUI() SwingUtilities.invokeLater(Invoker())
© 2006 矢木浩人