More Swing utilities: JTree COMP204, Bernhard Pfahringer Code snippets taken from Sun’s JTree demo example.

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing What is Swing? A part of The Java Foundation Classes Swing Look and feel Accessibility Java 2D (Java 2 onwards) Drag and Drop.
Advertisements

User Interfaces II GUI – Awt, Swing, Web
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Class diagram ECF MainFrame Package ECF3.ui (user interface) MenuBarMainPanel MainCenterPanel JButton(" MainPanelButtonNorth ")JButton(" MainPanelButtonSouth.
User Interface Design CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
Recursion practice. Problem 0 Using recursion (and no arrays), write the code to read in a series of numbers (until EOF) and then print them backwards.
Insert A tree starts with the dummy node D D 200 D 7 Insert D
Metric Converter What layout do we use? What is the class hierarchy? What listeners do we use? The code for this application is on our class web-site.
JEditorPane Chapter 18 - Student. (c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see.
GUI’s and eventhandlers in java Martin Jagersand.
Feb 18, 2000 Intermediate Containers. Global, Local and Static zGlobal/local are terms for variables in a program written in procedural-based language.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
Building a Web Browser CS1316: Representing Structure and Behavior.
Iterators CS 367 – Introduction to Data Structures.
Copyright 2003 Mudra Services1 SWING - JTabbedPane Helps stack pages of information into a single point of reference If information cannot be laid out.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Swing, part 2 Tutorial 07 1 / 31 Leonid Barenboim 25/4/2010.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling.
Trees CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Inheritance The Basics in Java. Definition  A class that is derived from another class is called a subclass (also a derived class, extended class, or.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Lecture 19 – Swing Control Programming Lecturer: Prof Jim Warren.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
JTree javax.swing.tree javax.swing.event. Components JTree and JTable COMPONENT – Model – Selection Model – Editor – Renderer.
Document Object Model DOM. Agenda l Introduction to DOM l Java API for XML Parsing (JAXP) l Installation and setup l Steps for DOM parsing l Example –Representing.
AITI Lecture 18 Introduction to Data Structure, Stack, and Queue Adapted from MIT Course 1.00 Spring 2003 Lecture 23 and Tutorial Note 8 (Teachers: Please.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
Review_6 AWT, Swing, ActionListener, and Graphics.
JSplitPane & JTabbedPane
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
1 CSE 331 Composite Layouts; Decorators slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
OOP Basics Classes & Methods (c) IDMS/SQL News
Java Graphics Chris North cs3724: HCI. Presentations peter hou Vote: UI Hall of Fame/Shame?
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Java API Course Lecture Slides 7 June 2010 “ And you guys were putting.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
1 Iterators & the Collection Classes. 2 » The Collection Framework classes provided in the JAVA API(Application Programmer Interface) contains many type.
Advanced Swing Trees. Contents I.Introduction to Trees II. Simple Trees III. Editing Trees and Tree Paths IV. Node Enumeration V. Rendering Nodes VI.
A Quick Java Swing Tutorial
Tree Insert Animation.
Building and Traversing Trees
Nodes & Explorer Views Geertjan Wielenga Sun Microsystems.
Advanced Swing Trees.
Lecture No.03 Data Structures Dr. Sohail Aslam
Algorithm for deleting a node from a singly linked list
New Features in NetBeans Platform 6.5.
A Quick Java Swing Tutorial
עקרונות תכנות מונחה עצמים
PRG 421 Education on your terms/tutorialrank.com.
תכנות מכוון עצמים בשפת JAVA
null, true, and false are also reserved.
Unit 3 - The while Loop - Extending the Vic class - Examples
CSE 326: Data Structures Extra Slides on Nested Lists
Recursive GCD Demo public class Euclid {
Metric Converter What layout do we use? What is the class hierarchy?
A Quick Java Swing Tutorial
Chapter 8, Design Patterns Composite
Building Java Programs
COMP204 Bernhard Pfahringer (with input from Robi Malik)
Presentation transcript:

More Swing utilities: JTree COMP204, Bernhard Pfahringer Code snippets taken from Sun’s JTree demo example

Displaying/inspecting/modified hierarchical data

Jtree displays tree nodes // node data structure: DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series"); createNodes(top); JTree tree = new JTree(top); tree.addTreeSelectionListener(this);

TreeSelectionListener public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) return; Object nodeInfo = node.getUserObject(); if (node.isLeaf()) { BookInfo book = (BookInfo)nodeInfo; displayURL(book.bookURL); } else { displayURL(helpURL); }

Build up data structure private void createNodes(DefaultMutableTreeNode top) { DefaultMutableTreeNode category = null; DefaultMutableTreeNode book = null; category = new DefaultMutableTreeNode("Books for Java Programmers"); top.add(category); book = new DefaultMutableTreeNode(new BookInfo ("The Java Tutorial: A Short Course on the Basics", "tutorial.html")); category.add(book);

Panel nesting TreeDemo extends Jpanel JScrollPane treeView = new JScrollPane(tree); htmlPane = new JEditorPane(); htmlPane.setEditable(false); JScrollPane htmlView = new JScrollPane(htmlPane); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(treeView); splitPane.setBottomComponent(htmlView); splitPane.setDividerLocation(100); add(splitPane);