![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
The methods of most interest include the getCheckedIndices() method. This method returns an integer array that contains the zero-based indices of all items with selected check boxes. The getItemChecked() method returns a zero-based index of the item whose check box state you want to examine. The setItemChecked() method takes two arguments. The first argument is the index of the item whose check box state you want to set, and the second argument is the value that indicates the current state of the check box. The CheckedListBox control has most of the same properties that the ComboBox and the ListBox controls have. The one I use most often is the selectedIndexChanged() event.
Listing 8.2 This Program Shows the Event Handlers That Use a Combo Box, a List Box, and a Checked List Box Control 1 private void listBox1_selectedIndexChanged(Object source, Event e) 2 { 3 label1.setText( "The selected item is " + ⇒listBox1.getSelectedItem() ); 4 } 6 private void checkedListBox1_selectedIndexChanged(Object source, ⇒Event e) 7 { 8 label1.setText( "The selected item is " + ⇒checkedListBox1.getSelectedItem() ); 9 } 10 11 private void comboBox1_selectedIndexChanged(Object source, Event e) 12 { 13 label1.setText( "The selected item is " + comboBox1.getText() ); 14 }
ListView and TreeView ControlsThe icon for the ListView control is shown here:
When you add a ListView control to your form, four lines of source code are added to set the default ListView control properties. These are shown in the following example: listView1.setLocation(new Point(32, 16)); listView1.setSize(new Point(208, 112)); listView1.setTabIndex(0); listView1.setText("listView1"); Youll find various methods in the ListView class to fulfill your programming needs. The getSelectedItems() method returns an array of currently selected list items. The insertItem() method takes four arguments. The first argument is an index for a new item you want to insert. The second argument is a string containing the text for the new item. The third argument is an integer that will be an index into the image list for this item. The fourth and final argument is an integer that will be a handle to external data to be stored by this item. The ListView control has most of the same events that other controls have. There are, though, two events that are different for this control. The itemActivate event occurs when an item is activated. The itemDrag event occurs when the user begins dragging an item. The TreeView control is encapsulated in a TreeView class. This control displays a generic Windows TreeView control. Heres the icon that appears in the Toolbox for the TreeView control:
Another property youll find important is the hotTracking property. This determines whether nodes give feedback when the mouse is moved over them. The showLines property lets you set whether lines will be displayed between sibling nodes, and between parent and child nodes. The showPlusMinus property lets you determine whether plus/minus buttons are shown next to parent nodes. The showRootLines property lets you set whether lines are displayed between root nodes. When a TreeView control is added to your form, four lines of default source code are added to your program. They are shown in the following example: treeView1.setLocation(new Point(48, 168)); treeView1.setSize(new Point(120, 72)); treeView1.setTabIndex(1); treeView1.setText("treeView1"); Now lets look at some of the more important methods in the TreeView control. The getSelectedNode() method gets the currently selected node in the TreeView control. The insertNode() method inserts a node into the TreeView control. It inserts it as a root node at the specified position. There are various very important events for a TreeView control. The first one is the afterExpand event. This happens when a node has been expanded. The afterLabelEdit event is triggered when the text of a node has been edited by the user. The afterSelect event happens when a selection has been changed. The beforeCollapse event occurs when a node is about to be collapsed. The beforeExpand event takes place when a node is just about to be expanded. HScrollbar and VScrollbar ControlsIn this section, Im going to talk about these two controls together. The HScrollbar control is encapsulated in an HScrollbar class, and the VScrollbar control is encapsulated in a VScrollbar class. Both of these controls can be placed on a form. They allow users to scroll an item. The icons for the HScrollbar control (on the left) and the VScrollbar control (on the right) are shown here:
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |