/**
* This example combines JList and JScrollPane The common use
* @author Wfei
*
*/
public class JListKnow extends JFrame
{
JList jListKnow01;
JList jListKnow02;
JScrollPane jScrollPane02; JSplitPane jSplitPane;
JPanel jPanelTop;
JPanel jPanelBottom;
public JListKnow()
{
this.setBounds(300, 100, 500, 500);
this.setTitle("JList Two ways of using : Recommend the second way to use it ");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jPanelTop = new JPanel();
jPanelBottom = new JPanel(); jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,jPanelTop,jPanelBottom);
jSplitPane.setDividerLocation(225); this.add(jSplitPane); String[] values = new String[]{"CCCCCC","AAAAAAAA","CCCCCC","DDDDDDD","EEEEEEEEEEEE","FFFFFFFFFFF","HHHHHHHHHHHH"};
/********************************JList The first way to use it *************************************/
jListKnow01 = new JList(values); // Set default selection
jListKnow01.setSelectedIndex(1); // Get the index of the selected item
int index = jListKnow01.getSelectedIndex();//JOptionPane.showMessageDialog(null, index+": Was chosen ");
int[] indexS = jListKnow01.getSelectedIndices();
// Get the value of the selected item
String value = (String) jListKnow01.getSelectedValue();
// String[] svalues = (String[]) jListKnow01.getSelectedValues(); // Set the selection mode of the list The default is multiple choice mode
jListKnow01.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jPanelTop.add(jListKnow01);
/********************************JList The second way to use it : recommend *************************************/
/******************************** Build lists from models ********************************/
// Instantiation model
DefaultListModel defaultListModel = new DefaultListModel();
// Add elements to the model
for (int i = 0; i < values.length; i++)
{
defaultListModel.addElement(values[i]);
}
// Delete all elements in the model
// defaultListModel.removeAllElements();
// Remove elements from the model according to the index , Maybe because there is no such index, the second error will be reported
// defaultListModel.remove(0);
// Remove elements from the model based on values , If there are multiple identical values , Then remove the value of the first index , without , No mistake.
defaultListModel.removeElement("CCCCCC");
// Replace the element at the designated index
defaultListModel.setElementAt(" Ha ha ha ", 1);
// Instantiate according to the model JList
jListKnow02 = new JList(defaultListModel); jScrollPane02 = new JScrollPane(jListKnow02); jPanelBottom.add(jListKnow02);
}
public static void main(String[] args)
{
JListKnow jListKnow = new JListKnow();
jListKnow.setVisible(true);
}
}

JAVA GUI Study - JList list 、JScrollPane Scroll bar component learning more related articles

  1. JAVA GUI Study - JPopupMenu Right click menu component learning

    public class JPopmenuKnow { public void test() { // Add a right-click menu to the table JMenuItem jMenuItemFileInfo = new JMe ...

  2. Java GUI: take JPanel Added to the JScrollPane

    Goals achieved : Because there are a lot of Java GUI Components , So here we use JPanel The panels enclose these components , In use JScrollPane Roll problem 1: The layout is mixed together JPanel It has its own default layout , therefore ...

  3. JAVA GUI Programming learning notes Directory

    2014 Summer vacation JAVA GUI Programming learning notes Directory 1.JAVA And GUI Programming overview 2.JAVA And GUI Programming layout 3.JAVA And GUI Programming Frame window 4.JAVA And GUI Programming event monitoring mechanism 5.JAVA And ...

  4. Java GUI Programming 4--- Tag components JLabel

    Java GUI Programming 4--- Tag components JLabel 2018 year 06 month 11 Japan 22:06:58 Blue blue 223 Read the number 12103 more Personal classification : Java Book excerpts My column : Java Swing The graphical interface ...

  5. amazeui Learning notes --css( Common components 8)-- list list

    amazeui Learning notes --css( Common components 8)-- list list One . summary 1. Link list : It's a list of multiple links , Use  <ul>  Structure nested link list , add to  .am-list. still ui package ...

  6. amazeui Learning notes --css( Common components 5)-- Comment list Comment

    amazeui Learning notes --css( Common components 5)-- Comment list Comment One . summary 1.am-comment: Use am-comment To declare the comment object , This is on article Inside , although article ...

  7. Writing in learning Java GUI Before

    Java GUI Just use Java Language to develop desktop applications , and Java Three more Java GUI library , Respectively AWT,Swing and SWT/JFace. What we need to learn now is Swing library . Postscript : Developing desktop applications , More than one technology , Now? ...

  8. java Gui Programming Event monitoring mechanism

    1.     GUI Introduction to programming In the past study , We all use command interaction : for example : stay DOS Command line through javac java Command to start the program . The way software interacts :   1. Command interaction mode    The book management system ...

  9. Ten . The graphical interface (GUI) Design 9. Lists and combo boxes

    Lists and combo boxes are another kind of interface components for users to choose from , Used to select items in a group , The combo box also allows you to enter a new selection . list list (JList) It is shown as a list box in the interface , yes JList Class or its subclasses . The program can add more than one text to the list box ...

Random recommendation

  1. Ubuntu 14.04 Configure static IP

    The command line manually configures static IP More trouble , Record here for future reference . 1,ubuntu The network profile of is in : # /etc/network/interfaces // In this document 2, The default installation is , Network configuration is using DHCP Automatically assigned I ...

  2. OpenLayers Learning notes 5—— Use jQuery UI Realize query and label (UI piece )

    There have been a lot of things recently , The pressure from the boss is also very high . Frequent business trips , In addition, both project and individual research have to keep up with , I'm going to hand in my thesis this month , And write patents , I just have time to learn other things . About OpenLayers I won't write too much detailed implementation in my blog ( Online ...

  3. make: *** No rule to make target `out

    according to google Guidelines , It's been a good journey , Last make -j5 when :make: *** No rule to make target `dalvik/vm/mterp/out/InterpAsm-x86 ...

  4. php Expand the development of practical course (1)

    My development environment : Ubuntu16.04 apt Installed by php5.6, apache,mysql etc. Because my machine uses apt Installed by php, So I'm going to start from scratch in the most streamlined way , Compile and install a php5.4 ...

  5. Python/MySQL( One 、 Basics )

    Python/MySQL( One . Basics ) mysql: MYSQL : It's a software for managing files -socket Server side ( Start... First ) - Local file operation - analysis Instructions [SQL sentence ] - Client software ( All kinds of guests ...

  6. 14 fragment Pass value

    Two fragment Pass value Mode one Layout file code : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  7. As Xiaobai , How to learn Web The front-end development ?

    As a person who has written code for so many years , I won't tell you that I was self-taught in the beginning , Because at the beginning, it's really boring , I can't go on learning , So I signed up for a training ( Shangyuan Education ) The place of , After all, I paid the money , In an unconvinced spirit , Just give birth to yourself ...

  8. c The accumulation of some fallible knowledge of language

    1. #ifdef  and #if defined The difference between : The latter can form complex precompile conditions , And if it's a single macro definition , Both of them have the same effect . 2.#if 0 { code }#endif    ...

  9. Django Rest framework The parser of the framework

    Parser serialize ***** Request data for verification Yes queryset Serializing Pagination route View Renderers

  10. C# Serialization and deserialization of classes in

    explain : This article demonstrates writing a class to Notepad after serialization and reading it from notepad and deserializing it as an object 1. First create a class , At the same time, the class must be identified as Serializable, as follows : [Serializable] public class Regio ...