Lists Assignment Help

Assignment Help: >> GUI elements >> Lists

Lists:

The JList component is different from the drop-down list in the previous section. Where as the JComboBox drops down when activated, the JList component occupies a fixed number of lines. The user can select a single string or a number of strings.

The simplest way to create a list is first to create an array containing the choices available and then to pass this array to the JList constructor.

String []data = {"brendan", "anton", "barbara", "martin" }; JList nameList = new JList(data);

We can now use nameList to reference the list of names.

There are a number of methods that can be used to modify items in a list and to select the items that have been clicked. Some of the more important ones are described below:

  • public Object [] getSelectedValues() returns an array of  Object that contains references to the items that have been selected. For example, the code: Object [] selectedNames = nameList.getSelectedValues( ); places references to the data array strings that have been selected by the user into the Object array selectedNames.
  • public int [] getSelectedIndices() returns an array of all the selected indices in increasing order.

If you retrieve the ListModel for a JList, using getModel(), you can also identify the object at each index of the JList, for example you can retrieve the string at index 1 of the nameList as follows:

nameList.getModel( ).getElementAt(1);

The component JList does not automatically provide scrolling. So, if you wish to have more choices in your list than you wish to allow space for in your GUI design you will need to provide scrolling for your list. This is quite easily done; you simply have to place your JList component inside a JScrollPane object, which automatically manages the creation of the scroll bars as necessary. The code to achieve this is given below:

JScrollPane scrollList = new JScrollPane(nameList);

The component scrollList is the same as the list nameList but now has a vertical scroll bar associated with it whenever there are more items in the list than can be displayed in the window. Details of the many features of the JScrollPane can be found in the Java reference documentation.

 

Java Assignment Help - Java Homework Help

Struggling with java programming language? Are you not finding solution for your Lists homework and assignments? Live Lists experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Lists homework help, java assignment help and Lists projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.

Why Expertsmind for assignment help

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving java programming language queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd