SwingAdvanced Controls
JColorChooser
JColorChooser     Constructors           public JColorChooser()           public JColorChooser(Color clr)                 ...
JColorChooser     Event Handling           Retrieve ColorSelectionModel                  Register ChangeListener object   ...
JColorChooser     Method          Color getColor()          void setColor()          showDialog(Component, String, Color)
JList
JList        Constructors              public JList()              public Jlist(Object[] items)              public Jlist(...
JList        Event Handling              Create Jlist              Create JScrollPane and pass JList              Add JScr...
JList        Method             public void setSelectionMode(int selectMode)
JList        Method             public void setLayoutOrientation(layoutOrient)
JList        Method             public void setVisibleRowCount(int count)
JList        Event Handling              Register ListSelectionListener              Handle valueChanged() method
JList        Method             public void clearSelection()             public int getSelectedIndex()             public ...
JList        Set and Select               public void setListData(Object[] items)               public void setSelectedInd...
JComboBox
JComboBox    Constructors          public JComboBox()          public JComboBox(Object[] items)          public JComboBox(...
JComboBox    Steps            Create a instance of JComboBox            Add it into container
JComboBox    Event Handling          Register ActionListener                 Handle actionPerformed() method          Regi...
JComboBox    Method         public void addItem(Object item)         public int getItemCount()         public int getSelec...
JComboBox    Method         public void setEditable(Boolean editable)         public void setSelectedIndex(int index)     ...
JTable
JTable      Constructors            public JTable()            public JTable(int numRows, int numColumns)            publi...
JTable     Display
JTable      Drawbacks             All columns are of same width by default             Ellipsis is used for displaying dat...
JTable     Creating a Custom JTable           AbstractTableModel           DefaultTableModel
AbstractTableModel      public int getRowCount()      public int getColumnCount()      public Object getValueAt(int row, i...
Steps:         Instantiate data model class         Instantiate JTable object         setData()
Event Handling      Register a MouseListener             Handle mouseClicked() method
JTree
Constructing a JTree       Create an instance of DefaultMutableTreeNode       Create an instance of a JTree
Constructing a JTree       Create DefaultMutableTreeNode instance       Add branch nodes       Add leaf nodes       Enclos...
Constructing a JTree
Event Handling      Register a TreeSelectionListener             Handle valueChanged() method      Register a TreeExpansio...
JTabbedPane
Constructing a JTabbedPane      public JTabbedPane()      public JTabbedPane(int placement)
Adding Tabs        Create JTabbedPane instance        Create JPanel instance for each tab        Add the component in the ...
Event Handling      Register a ChangeListener             Handle stateChanged() method
JSplitPane
Constructing a JSplitPane       public JSplitPane()       public JSplitPane(int orientation)       public JSplitPane(int, ...
Methods     void setOneTouchExpandable(boolean)     void setDividerLocation(int)
Upcoming SlideShare
Loading in …5
×

Module 4

673 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
673
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Module 4

  1. 1. SwingAdvanced Controls
  2. 2. JColorChooser
  3. 3. JColorChooser Constructors public JColorChooser() public JColorChooser(Color clr) | Color clr = new Color(25,135,200);
  4. 4. JColorChooser Event Handling Retrieve ColorSelectionModel Register ChangeListener object Handle stateChanged method
  5. 5. JColorChooser Method Color getColor() void setColor() showDialog(Component, String, Color)
  6. 6. JList
  7. 7. JList Constructors public JList() public Jlist(Object[] items) public Jlist(Vector vecItems)
  8. 8. JList Event Handling Create Jlist Create JScrollPane and pass JList Add JScrollPane to container
  9. 9. JList Method public void setSelectionMode(int selectMode)
  10. 10. JList Method public void setLayoutOrientation(layoutOrient)
  11. 11. JList Method public void setVisibleRowCount(int count)
  12. 12. JList Event Handling Register ListSelectionListener Handle valueChanged() method
  13. 13. JList Method public void clearSelection() public int getSelectedIndex() public int[] getSelectedIndices() public boolean isSelectionEmpty()
  14. 14. JList Set and Select public void setListData(Object[] items) public void setSelectedIndex(int index) public void setSelectedIndices(int[]indices)
  15. 15. JComboBox
  16. 16. JComboBox Constructors public JComboBox() public JComboBox(Object[] items) public JComboBox(Vector vecItems)
  17. 17. JComboBox Steps Create a instance of JComboBox Add it into container
  18. 18. JComboBox Event Handling Register ActionListener Handle actionPerformed() method Register ItemListener Handle itemStateChanged() method
  19. 19. JComboBox Method public void addItem(Object item) public int getItemCount() public int getSelectedIndex() public object getSelectedItem()
  20. 20. JComboBox Method public void setEditable(Boolean editable) public void setSelectedIndex(int index) public void setSelectedItem(Object item)
  21. 21. JTable
  22. 22. JTable Constructors public JTable() public JTable(int numRows, int numColumns) public JTable(Object[][] data, Object[]column) public JTable(Vector data, Vector columns) public JTable(TableModel model)
  23. 23. JTable Display
  24. 24. JTable Drawbacks All columns are of same width by default Ellipsis is used for displaying data Horizontal scrolling will not be activatedbecause of ellipsis
  25. 25. JTable Creating a Custom JTable AbstractTableModel DefaultTableModel
  26. 26. AbstractTableModel public int getRowCount() public int getColumnCount() public Object getValueAt(int row, int column) fireTableDataChanged()
  27. 27. Steps: Instantiate data model class Instantiate JTable object setData()
  28. 28. Event Handling Register a MouseListener Handle mouseClicked() method
  29. 29. JTree
  30. 30. Constructing a JTree Create an instance of DefaultMutableTreeNode Create an instance of a JTree
  31. 31. Constructing a JTree Create DefaultMutableTreeNode instance Add branch nodes Add leaf nodes Enclose the tree in scrollpane Add scrollpane to frame
  32. 32. Constructing a JTree
  33. 33. Event Handling Register a TreeSelectionListener Handle valueChanged() method Register a TreeExpansionListener Handle treeExpanded() method Handle treeCollapsed() method Register a TreeWillExpandListener Handle treeWillExpand() method Handle treeWillCollapse() method
  34. 34. JTabbedPane
  35. 35. Constructing a JTabbedPane public JTabbedPane() public JTabbedPane(int placement)
  36. 36. Adding Tabs Create JTabbedPane instance Create JPanel instance for each tab Add the component in the respective panels Use the addTab() method of JTabbedPane to add thepanel
  37. 37. Event Handling Register a ChangeListener Handle stateChanged() method
  38. 38. JSplitPane
  39. 39. Constructing a JSplitPane public JSplitPane() public JSplitPane(int orientation) public JSplitPane(int, boolean) public JSplitPane(int, boolean, Component,Component)
  40. 40. Methods void setOneTouchExpandable(boolean) void setDividerLocation(int)

×