~/home_Jython/JFC-Swing/java.sun.com/_TableListSelectionDemoProject/TableListSelectionDemo.py
|INDEX| Python.use(better, Java) #Jython
- How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) ¶
- TableListSelectionDemo.java ¶
》作業中です《
#! /usr/bin/env python # coding: utf-8 ## ---------------------------------------- ## ## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部 ## ## ---------------------------------------- #...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 """ >>> tips() >>> ## ---------------------------------------- >>> None version: #1.0.24 """ ## ---------------------------------------- bash """ stty erase ^H PS1="$ " alias jython="~/home_Jython/_release/jython2.5.0/bin/jython" """ ## ---------------------------------------- Java/Jython """ alias java="/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java" alias javac="/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/javac" JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home" JYTHON_HOME_FALLBACK="/Users/sketch/jython2.5b3" """ ## ---------------------------------------- JFC/Swing """ @http://java.sun.com/docs/books/tutorial/uiswing/examples/components/SplitPaneDemoProject/src/components/SplitPaneDemo.java """ ## ---------------------------------------- demo: java """ $ cd ~/download/demo_Jython/java.sun.com/docs-books-tutorial-uiswing-example/ $ cd events-TableListSelectionDemoProject/src/ $ $ javac events/TableListSelectionDemo.java $ ls -l events/ total 56 -rw-r--r-- 1 sketch staff 1452 3 23 10:40 TableListSelectionDemo$1.class -rw-r--r-- 1 sketch staff 462 3 23 10:40 TableListSelectionDemo$2.class -rw-r--r-- 1 sketch staff 1842 3 23 10:40 TableListSelectionDemo$SharedListSelectionHandler.class -rw-r--r-- 1 sketch staff 4059 3 23 10:40 TableListSelectionDemo.class -rw-r--r-- 1 sketch staff 8214 1 28 19:00 TableListSelectionDemo.java $ java events/TableListSelectionDemo $ """ ## ---------------------------------------- demo: jython """ $ cd ~/home_Jython/JFC-Swing/java.sun.com/_TableListSelectionDemoProject/ $ jython -i TableListSelectionDemo.py """ ## ---------------------------------------- """ /* * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved. */ package events; /* * TableListSelectionDemo.java requires no other files. */ """ from java.awt import BorderLayout from java.awt import GridLayout from java.awt.event import ActionListener from javax.swing import BorderFactory from javax.swing import BoxLayout from javax.swing import JComboBox from javax.swing import JFrame from javax.swing import JLabel from javax.swing import JPanel from javax.swing import JScrollPane from javax.swing import JSplitPane from javax.swing import JTable from javax.swing import JTextArea from javax.swing import ListSelectionModel from javax.swing import ScrollPaneConstants from javax.swing.event import ListSelectionListener ## ---------------------------------------- def tips(): createAndShowGUI() """ * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. """ def createAndShowGUI(): ##//Create and set up the window. frame = JFrame( title = "TableListSelectionDemo", defaultCloseOperation = JFrame.EXIT_ON_CLOSE, ) ##//Create and set up the content pane. demo = TableListSelectionDemo( opaque = True, ) frame.contentPane = demo ##//Display the window. frame.pack() frame.visible = True ## ---------------------------------------- class TableListSelectionDemo(JPanel): def __init__(self, *args, **keys): newline = "\n" JPanel.__init__( self, layout = BorderLayout(), *args, **keys) columnNames = "French","Spanish","Italian", tableData = [ ["un" ,"uno" ,"uno" ], ["deux" ,"dos" ,"due" ], ["trois" ,"tres" ,"tre" ], ["quatre","cuatro","quattro"], ["cinq" ,"cinco" ,"cinque" ], ["six" ,"seis" ,"sei" ], ["sept" ,"siete" ,"sette" ], ] class SharedListSelectionHandler(ListSelectionListener): def valueChanged(self, e): lsm = e.source firstIndex = e.firstIndex lastIndex = e.lastIndex isAdjusting = e.valueIsAdjusting output.append( "Event for indexes %d - %d" "; isAdjusting is %s" "; selected indexes:" %(firstIndex, lastIndex, isAdjusting)) if lsm.isSelectionEmpty(): output.append(" <none>") else: ##// Find out which indexes are selected. minIndex = lsm.minSelectionIndex maxIndex = lsm.maxSelectionIndex for i in range(minIndex, maxIndex+1): if lsm.isSelectedIndex(i): output.append(" %d"%i) output.append(newline) output.caretPosition = output.document.length table = JTable(tableData, columnNames) listSelectionModel = table.selectionModel listSelectionModel.addListSelectionListener( SharedListSelectionHandler()) table.selectionModel = listSelectionModel tablePane = JScrollPane(table) tablePane = JScrollPane( table, preferredSize = (420,130), ) ##//Build control area (use default FlowLayout). controlPane = JPanel() modes = [ "SINGLE_SELECTION" , "SINGLE_INTERVAL_SELECTION" , "MULTIPLE_INTERVAL_SELECTION", ] comboBox = JComboBox( modes, selectedIndex = 2, ) class ComboBox_ActionListener(ActionListener): def actionPerformed(self, e): newMode = comboBox.selectedItem listSelectionModel.selectionMode = getattr( ListSelectionModel, newMode) output.append("----------Mode: %s----------\n"%newMode) comboBox.addActionListener(ComboBox_ActionListener()) controlPane.add(JLabel("Selection mode:")) controlPane.add(comboBox) ##//Build output area. output = JTextArea( 1,10, editable = False, ) outputPane = JScrollPane( output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED, ) ##//Do the layout. splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT) self.add(splitPane, BorderLayout.CENTER) topHalf = JPanel( minimumSize = (250,50), preferredSize = (200,110), border = BorderFactory.createEmptyBorder(5,5,0,5), ) topHalf.layout = BoxLayout(topHalf, BoxLayout.LINE_AXIS) listContainer = JPanel(GridLayout(1,1)) tableContainer = JPanel( GridLayout(1,1), border = BorderFactory.createTitledBorder("Table"), ) tableContainer.add(tablePane) topHalf.add(listContainer) topHalf.add(tableContainer) splitPane.add(topHalf) bottomHalf = JPanel( BorderLayout(), preferredSize = (450,110), ) bottomHalf.add(controlPane, BorderLayout.PAGE_START) bottomHalf.add(outputPane, BorderLayout.CENTER) splitPane.add(bottomHalf) ## ---------------------------------------- ## ---------------------------------------- from time import ctime from sys import argv, version def inform(n=60): print("="*n) print("Version: %s"%version.split("\n")[0]) print("Module : %s"%argv[0].split("/")[-1]) print("Date : %s"%ctime()) print("="*n) ## ---------------------------------------- from doctest import testmod if __name__=='__main__': inform() testmod() ## ========================================
Last updated♪2010/03/25