TAILIEUCHUNG - Java Swing phần 6

để cung cấp khoảng cách giữa các nhóm của các thành phần thanh công cụ. Kích thước bình thường lên đến thanh công cụ, mặc dù bạn có thể chỉ định kích thước của dấu phân cách rõ ràng nếu bạn muốn. bảo vệ void paintBorder (Graphics g) Ghi đè paintBorder () | Java Swing - O Reilly public JTree TreeNode root public JTree TreeNode root boolean asksAllowsChildren These constructors build new trees using the node root as the root of the tree. They also use the DefaultTreeModel as their model. public JTree TreeModel model Builds a tree using the model provided. The model argument contains the root of the tree. public JTree Object value public JTree Vector value public JTree Hashtable value These convenience constructors build a DefauitTreeModei object and use the inner class to populate the tree using the value argument as children. If any element in value is itself an Obj ect a Vector or a Hashtable a node will be built for that element and its contents become children of the node. This recursive process continues until all elements and their contents have been explored. The last constructor is great for simple data structures that you want to display as a tree. Figure shows the tree that results when you display a hash table. Figure . A JTree built using a Hashtable and the DefaultTreeModel Even though this tree is larger than the tree of Figure it takes less code to set it up as follows. A Simple test to see how we can build a tree and populate it. import . import . import . import . - 496 - Java Swing - O Reilly import . public class ObjectTree extends JFrame JTree tree String sampleData Amy Brandon Bailey Jodi Trent Garrett Paige Dylan Donn Nancy Donald Phyllis John Pat public ObjectTree super Hashtable Test setSize 400 300 addWindowListener new BasicWindowMonitor public void init Hashtable h new Hashtable build up the hashtable using every other entry in the String as a key followed by a value which is a String for int i 0 i i 2 sampleData i 0 sampleData i 1 tree new JTree h getContentPane .add tree public static void main String args ObjectTree tt new ObjectTree

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.