Selection of JList item

hi friends
i am using JList component.i have added many item in Jlist.by keyboard up and down arrow key i can make them highlighted and then select. but i want few item of JList never highlighted and select when i press up and down arrow key . For example, If i do not want to select 2nd item in the list then by pressing down arrow key selection should be jumped from first to third item skipping second item.
How to do that?

I might be wrong but I think you need to code for it.
I have created a code using key binding. To use if you need to skip an item you need to hold down the control key and use the up and down arrow to navigate and once you have selected an item release control key and press enter, vice-versa.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ListFocusDemo extends JFrame {
    public void createAndShowUI() {
        final JList myList = new JList(new String[] {"My data 1","My data 2",
        "My data 3","My data 4"});
        JScrollPane scrollPane = new JScrollPane(myList);
        InputMap map = myList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "myAction");
        myList.getActionMap().put("myAction", new AbstractAction() {
            public void actionPerformed(ActionEvent evt) {
                int lead = myList.getLeadSelectionIndex();
                if(lead > -1 && !myList.isSelectedIndex(lead)) {
                    myList.getSelectionModel().addSelectionInterval(lead, lead);
                } else if(lead > -1 && myList.isSelectedIndex(lead)) {
                    myList.getSelectionModel().removeSelectionInterval(lead, lead);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(scrollPane, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    public static void main(String[] args) {
        Runnable run = new Runnable() {
            public void run() {
                new ListFocusDemo().createAndShowUI();
        SwingUtilities.invokeLater(run);
}

Similar Messages

  • Selecting a jlist item and placing it in view

    i have 100 items in a jlist. then i scrolled to the bottom of the list.....so now the first item is not in view anymore.
    i have a button on top that retrieves rows and rebuilds the jlist.
    which it does.
    however, if i am at the bottom of the list and hit the button i want the first item to be selected and viewed in the screen.
    dbase_list.setSelectedIndex(0); ---> selects the first item
    but its not in view till i scroll back up again.
    how do i select and place the first item in the users view after i hit the button? is there a method that does it?
    thanks

    Add this code in ur constrcutor
    list.setAutoscrolls(true);
    list.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    list.ensureIndexIsVisible(list.getSelectedIndex());
    });

  • Permeantly select a JList Item.

    how would i permeantly select a item in a Jlist? ie. Even if the user clicks it it wont uncheck, it will always be selected.
    There will be other items in the Jlist which they may select and deselect but one which they cannot and stays selected.
    Thanks

    Hi,
    I would use the CellRenderer since selection if just the renderer drawing it. The example below should demonstrate what I mean.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class PermCellRenderer extends JLabel implements ListCellRenderer
      private int[] permIndices;
      public PermCellRenderer()
        this( null );
      public PermCellRenderer( int[] permIndices )
        setOpaque( true );
        this.permIndices = permIndices;
        System.out.println( this.permIndices[0] );
      private boolean isPermanent( int index )
        boolean outVal = false;
        if( permIndices != null )
          for( int i = 0; i < permIndices.length; ++i )
            if( permIndices[i] == index )
              outVal = true;
              break;
        return( outVal );
      public Component getListCellRendererComponent( JList list, Object value,
                                                     int index,
                                                     boolean isSelected,
                                                     boolean cellHasFocus )
        setText( value.toString() );
        if( isPermanent( index ) || isSelected )
          setBackground( list.getSelectionBackground() );
          setForeground( list.getSelectionForeground() );
        else
          setBackground( list.getBackground() );
          setForeground( list.getForeground() );
        return( this );
    public class PermListExample extends JFrame
      JList list;
      public PermListExample()
        super( "Permanent List Selection" );
        String[] data = { "First", "Second", "Permanent", "Fourth", "Fifth" };
        int[] perm = { 2 };
        list = new JList( data );
        list.setCellRenderer( new PermCellRenderer( perm ) );
        list.setVisibleRowCount( 10 );
        getContentPane().add( list );
        pack();
      public static void main(String[] args)
        new PermListExample().setVisible( true );
    }Enjoy,
    Manfred.

  • Double click for JList items selection

    I would like to select JList items only by double clicking on them. I can write a mouse listener for detecting double clicks by my own (and handle it afterwards), by please tell me how to turn the default behavior off (selecting items by clicking one time).
    Thanks in advance
    Marek

    I would like to select JList items only by double clicking on them. Well the standard is to select or highlight on a mouseClick or by using the arrow keys on the keyboard.
    Then once you have a selected item you can perform and Action on the item by double clicking or by using the enter key. Remember you should always be able to use either the keyboard or the mouse to perform any given function.
    This posting shows my solution for the above scenario:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=626866

  • JList item selected is displayed twice. Please Assist

    Folks,
    I have this strange behaviour when I select an item from the JList.
    When I select the an item, it gets displayed twice.
    Can anyone tell me why this is being displayed twice?
    I am also checking the Java Sun Swing tutorials site..but no luck as yet.
    Attached is a short class.
    If you click on Black or Blue etc ,it gets displayed twice...
    public class JListDemo extends JFrame{
    private JList colorList;
    private Container c;
    private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
    public JListDemo() {
    super("JList Demo");
    c = getContentPane();
    c.setLayout(new FlowLayout());
    /** Create a List */
    colorList = new JList(colorNames);
    colorList.setVisibleRowCount(3);
    colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    c.add(new JScrollPane(colorList));
    //** Set up Event Handler.
    colorList.addListSelectionListener(
    new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e)
    System.out.println(colorList.getSelectedValue());
    setSize(1000,550);
    show();
    public static void main(String[] args) {
    JListDemo JListDemo1 = new JListDemo();
    }

    in your ListSelectionListener you must check if the event is one of multiple change events. In your case you get one event when the mouse first selects an item and possible more when you move the cursor over the other entries. If you are only interested in the final selection check if e.getValueIsAdjusting() is false.
    // not interested in events if they are not final
    if (e.getValueIsAdjusting())
        return;
    // do what ever you want
    System.out.println(colorList.getSelectedValue());
    ...Hope this helps!

  • Delete Selected JList Item on Pressing Delete Key

    Hi,
    I have to delete selected JList item ((in JFrame using java Swing) after pressing Delete key. Please provide me code for this.
    Thanks
    Nitin

    Again read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists and [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings.
    Are you sensing a common theme here? Do some reading on your own. The tutorial has most of the information you need.

  • Problem in refreshing the combo box on selection of an item in another comb

    I have a situation where values to be displayed in 2nd combo box depends on the selection of an item from the 1st combo box.
    Problem observed:
    The 2nd combo box is not getting refreshed if the selected item from the 1st combo box has mapping to more than 10 items.
    for ex:
    A - AA, AB, AC, AD, AE, AF
    B - BA, BB, BC, BD, BE, BF, BG, BH, BI, BJ, BK, BL, BM, BN, BO, BP
    C - CA, CB, CC
    D - DA, DB, DC, DD
    1st combo box list:
    A
    B
    C
    D
    2nd combo box list:
    If the value selected from the first combo box is A, C, or D then 2nd combo box refreshes with repective values. But when the value selected is B, then 2nd combo box is not getting refreshed with respective values.
    Combo Model for 1st combo box:
    public class proCLMLossTypeComboModel implements javax.swing.ComboBoxModel
    package nz.co.towerinsurance.quantum.claims.pro;
    import javax.swing.*;
    import java.util.*;
    import CoreProduct.mbsoPRDLossCauseTypeList;
    import javax.swing.event.*;
    public class proCLMLossTypeComboModel implements javax.swing.ComboBoxModel
    Vector vector = null;
    mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst0 = null;
    public void setData(Vector vector)
    this.vector = vector;
    public int getSize()
    if(vector != null)
    return this.vector.size();     
    else
    return 0;
    public void addListDataListener(ListDataListener l)
    public void removeListDataListener(ListDataListener l)
    public Object getElementAt(int index)
    return this.vector.elementAt(index);     
    public Object getSelectedItem()
    return this.mbsoPRDLossCauseTypeListInst0;     
    public void setSelectedItem(Object anItem)
    mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst1 = (mbsoPRDLossCauseTypeList)anItem;
    this.mbsoPRDLossCauseTypeListInst0 = mbsoPRDLossCauseTypeListInst1;
    public Vector getData()
    return this.vector;     
    Combo Model for 2nd combo box:
    package nz.co.towerinsurance.quantum.claims.pro;
    import javax.swing.*;
    import java.util.*;
    import CoreProduct.mbsoPRDCauseTypeList;
    import javax.swing.event.*;
    public class proCLMCauseTypeComboModel implements javax.swing.ComboBoxModel
    Vector vector = null;
    mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst0 = null;
    public void setData(Vector vector)
    this.vector = vector;
    public int getSize()
    if(vector != null)
    return this.vector.size();     
    else
    return 0;
    public void addListDataListener(ListDataListener l)
    public void removeListDataListener(ListDataListener l)
    public Object getElementAt(int index)
    return this.vector.elementAt(index);     
    public Object getSelectedItem()
    return this.mbsoPRDCauseTypeListInst0;     
    public void setSelectedItem(Object anItem)
    mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst1 = (mbsoPRDCauseTypeList)anItem;
    this.mbsoPRDCauseTypeListInst0 = mbsoPRDCauseTypeListInst1;
    public Vector getData()
    return this.vector;     
    The Panel inside which these combo boxes are used:
    package nz.co.towerinsurance.quantum.claims.pro;
    import nz.co.towerinsurance.quantum.logger.MessageLogger;
    import nz.co.towerinsurance.quantum.claims.vmo.*;
    import nz.co.towerinsurance.quantum.utility.uhoUTLDialogueContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLModelHolder;
    import nz.co.towerinsurance.quantum.utility.uhoUTLInteraction;
    import nz.co.towerinsurance.quantum.utility.uhoUTLNotesContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLPrivacyContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLProcessImpContext;
    import nz.co.towerinsurance.quantum.help.*;
    import nz.co.towerinsurance.quantum.document.*;
    import nz.co.towerinsurance.quantum.task.*;
    import nz.co.towerinsurance.quantum.qtm.*;
    import nz.co.towerinsurance.quantum.claims.uhoCLMClientModel;
    import nz.co.towerinsurance.quantum.claims.utility.*;
    import MCType.*;
    import Claim.*;
    import Client.*;
    import Policy.*;
    import CoreProduct.*;
    import Security.*;
    import MCUtil.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.ButtonGroup.*;
    import java.text.*;
    public class proSummaryPanel extends proCLMPanelBase implements proCLMRefreshInterface, proCLMDeclineReasonInterface
    private static final MessageLogger msgLogger=MessageLogger.getLogger("claims.pro.proSummaryPanel");
    uhoCLMClientModel uhoCLMClientModelInst0 = null;
    Vector VectorInst0 = new Vector();
    JRadioButton jRdBtnSummaryPM = new JRadioButton();
    JRadioButton jRdBtnSummaryAM = new JRadioButton();
    ButtonGroup ButtonGroupInst0 = new ButtonGroup();
    JButton jBtnSummarySearch = new JButton();
    JLabel jLblSummaryCompanyName = new JLabel();
    JLabel jLblSummaryCauseType = new JLabel();
    JTextField jTxtFldSummaryAmountSaved = new JTextField();
    JTextField jTxtFldSummaryDateNotified = new JTextField();
    JTextField jTxtFldSummary = new JTextField();
    JTextField jTxtFldSummarySuburb = new JTextField();
    JLabel jLblSummaryCatCode = new JLabel();
    JLabel jLblSummaryLossDesc = new JLabel();
    JLabel jLblSummaryDateNotified = new JLabel();
    JLabel jLblSummaryCity = new JLabel();
    JLabel jLblSummaryTime = new JLabel();
    JLabel jLblSummaryDeclineReason = new JLabel();
    JCheckBox jChkBxNcbLost = new JCheckBox();
    JCheckBox jChkBxLegal = new JCheckBox();
    JCheckBox jChkBxNoBlameBonus = new JCheckBox();
    JLabel jLblSummaryPostCode = new JLabel();
    JTextField jTxtFldSummaryStreetName = new JTextField();
    JTextField jTxtFldSummaryLossDate = new JTextField();
    JTextField jTxtFldSummaryCity = new JTextField();
    JTextField jTxtFldSummaryTime = new JTextField();
    JLabel jLblSummaryLossType = new JLabel();
    JTextField jTxtFldSummaryPhone = new JTextField();
    JTextField jTxtFldSummaryCompanyName = new JTextField();
    JLabel jLblSummarySuburb = new JLabel();
    JTextArea jTxtArLossDescription = new JTextArea();
    JScrollPane jScrPnSummaryLossDesc = new JScrollPane(jTxtArLossDescription);
    JTextField jTxtFldSummaryDeclineReason = new JTextField();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel1 = this;
    JLabel jLblSummaryPhone = new JLabel();
    JTextField jTxtFldSummaryPostCode = new JTextField();
    JLabel jLblSummaryAmountSaved = new JLabel();
    JPanel jPnlSummaryCoy = new JPanel();
    JLabel jLblSummaryStreetName = new JLabel();
    Vector lossTypeVec = new Vector();
    JComboBox jCmbBxSummaryLossType = new JComboBox(lossTypeVec);
    proCLMLossTypeComboModel lossTypeComboModel = new proCLMLossTypeComboModel();
    Vector causeTypeVec = new Vector();
    JComboBox jCmbBxSummaryCauseType = new JComboBox();
    proCLMCauseTypeComboModel causeTypeComboModel = new proCLMCauseTypeComboModel();
    Vector CatCodeVec = new Vector();
    JComboBox jCmbBxSummaryCatCode = new JComboBox();
    proCLMCatCodeComboModel catCodeComboModel = new proCLMCatCodeComboModel();
    JLabel jLblSummaryLossDate = new JLabel();
    JButton jBtnSave = new JButton();
    JButton jBtnCancel = new JButton();
    Border border1;
    TitledBorder titledBorder1;
    Border border2;
    Border border3;
    TitledBorder titledBorder2;
    Border border4;
    TitledBorder titledBorder3;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    GridBagLayout gridBagLayout2 = new GridBagLayout();
    Border border5;
    TitledBorder titledBorder4;
    GridBagLayout gridBagLayout3 = new GridBagLayout();
    GridBagLayout gridBagLayout4 = new GridBagLayout();
    Component component1;
    Component component2;
    * @parameter uhoUTLInteraction ,mbsoSEMPrivilege
    * @return
    public proSummaryPanel(proQTMBase parent, uhoUTLInteraction inter,mbsoSEMPrivilege services)
    super(parent,inter,services);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    * Component initialization
    * @parameter
    * @return void
    private void jbInit() throws Exception
    component1 = Box.createHorizontalStrut(8);
    component2 = Box.createHorizontalStrut(8);
    jCmbBxSummaryLossType.setMinimumSize(new Dimension(225, 25));
    // set the combo models
    jCmbBxSummaryLossType.setModel(lossTypeComboModel);
    jCmbBxSummaryCauseType.setModel(causeTypeComboModel);
    jCmbBxSummaryCatCode.setModel(catCodeComboModel);
    // renderer for the loss type combo
         jCmbBxSummaryLossType.setRenderer(new DefaultListCellRenderer()
         public Component getListCellRendererComponent(JList list, Object value,
         int index, boolean isSelected, boolean cellHasFocus)
         mbsoPRDLossCauseTypeList mbsoPRDLossTypeListObj = (mbsoPRDLossCauseTypeList) value;
         String v = (mbsoPRDLossTypeListObj == null) ? null:mbsoPRDLossTypeListObj.GetLossTypeName().toString();
         return super.getListCellRendererComponent(list,v,index,isSelected,cellHasFocus);
         // key selection manager for loss type combo
         jCmbBxSummaryLossType.setKeySelectionManager(new javax.swing.JComboBox.KeySelectionManager()
         public int selectionForKey(char aKey,ComboBoxModel aModel)
         try
         Vector vector = lossTypeComboModel.getData();
         // prepare a character array witht the first letter of loss types in lower case
         char[] characterArray = new char[vector.size()];
         for(int i=0;i<vector.size();i++)
         mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst0 = (mbsoPRDLossCauseTypeList)vector.elementAt(i);
         char charac = mbsoPRDLossCauseTypeListInst0.GetLossTypeName().toString().toLowerCase().charAt(0);     
         characterArray[i] = charac;
         Character char1 = new Character(aKey);
         int index = 0;
         if(char1.isUpperCase(aKey))
         char char2 = char1.toLowerCase(aKey);
         index = java.util.Arrays.binarySearch(characterArray,char2);
         else
         index = java.util.Arrays.binarySearch(characterArray,aKey);
         if(index > 0)
         jCmbBxSummaryLossType.setSelectedIndex(index);
         else
         jCmbBxSummaryLossType.setSelectedIndex(0);
         jCmbBxSummaryLossType.repaint();
         if(index > 0)
         return index;
         else
         return 0;
         catch(Exception e1)
         msgLogger.fatal("Exception     : proSumamryPanel     : loss type combo key sel mgr : "+e1.getMessage());
         return 0;
         // renderer for cause type combo
         jCmbBxSummaryCauseType.setRenderer(new DefaultListCellRenderer() {
         public Component getListCellRendererComponent(JList list, Object value,
         int index, boolean isSelected, boolean cellHasFocus)
         mbsoPRDCauseTypeList mbsoPRDCauseTypeListObj = (mbsoPRDCauseTypeList) value;
         String v = (mbsoPRDCauseTypeListObj == null) ? null:mbsoPRDCauseTypeListObj.GetCauseTypeName().toString();
         return super.getListCellRendererComponent(list,v,index,isSelected,cellHasFocus);
         // key selection manager for loss type combo
         jCmbBxSummaryCauseType.setKeySelectionManager(new javax.swing.JComboBox.KeySelectionManager()
         public int selectionForKey(char aKey,ComboBoxModel aModel)
         try
         Vector vector = causeTypeComboModel.getData();
         // prepare a character array witht the first letter of loss types in lower case
         char[] characterArray = new char[vector.size()];
         for(int i=0;i<vector.size();i++)
         mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst0 = (mbsoPRDCauseTypeList)vector.elementAt(i);
         char charac = mbsoPRDCauseTypeListInst0.GetCauseTypeName().toString().toLowerCase().charAt(0);     
         characterArray[i] = charac;
         Character char1 = new Character(aKey);
         int index = 0;
         if(char1.isUpperCase(aKey))
         char char2 = char1.toLowerCase(aKey);
         index = java.util.Arrays.binarySearch(characterArray,char2);
         else
         index = java.util.Arrays.binarySearch(characterArray,aKey);
         if(index > 0)
         jCmbBxSummaryCauseType.setSelectedIndex(index);
         else
         jCmbBxSummaryCauseType.setSelectedIndex(0);
         jCmbBxSummaryCauseType.repaint();
         if(index > 0)
         return index;
         else
         return 0;
         catch(Exception e1)
         msgLogger.fatal("Exception     : proSumamryPanel     : cause type combo key sel mgr : "+e1.getMessage());
         return 0;
    jBtnSummarySearch.setBorder(BorderFactory.createRaisedBevelBorder());
    jBtnSummarySearch.setMaximumSize(new Dimension(119, 23));
    jBtnSummarySearch.setPreferredSize(new Dimension(65, 23));
    jBtnSummarySearch.setMnemonic(KeyEvent.VK_E); // 20/12
    jBtnSummarySearch.setText("Search");
    this.setLayout(gridBagLayout4);
    ButtonGroupInst0.add(jRdBtnSummaryPM);
    ButtonGroupInst0.add(jRdBtnSummaryAM);
    border1 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder1 = new TitledBorder(border1,"Where Is It Now?");
    border2 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    border3 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder2 = new TitledBorder(border3,"Where Is It Now?");
    border4 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder3 = new TitledBorder(border4,"Summary");
    border5 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder4 = new TitledBorder(border5,"Location of Vehicle/Boat");
    jScrPnSummaryLossDesc.setToolTipText("");
    jScrPnSummaryLossDesc.setFont(new java.awt.Font("SansSerif", 0, 12));
    jScrPnSummaryLossDesc.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jLblSummarySuburb.setText("Suburb");
    jLblSummarySuburb.setForeground(Color.black);
    jLblSummarySuburb.setPreferredSize(new Dimension(100, 17));
    jLblSummarySuburb.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummaryCompanyName.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCompanyName.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryCompanyName.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryCompanyName.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setToolTipText("");
    jTxtFldSummaryPhone.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryPhone.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLblSummaryLossType.setText("Loss Type");
    jLblSummaryLossType.setForeground(Color.black);
    jLblSummaryLossType.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossType.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummaryTime.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryTime.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryTime.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryTime.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCity.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCity.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryCity.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryCity.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setBackground(Color.cyan);
    jTxtFldSummaryLossDate.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryLossDate.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setFont(new java.awt.Font("SansSerif", 0, 12));
    jBtnSave.setToolTipText("");
    jBtnSave.setBorder(BorderFactory.createRaisedBevelBorder());
    jBtnSave.setMnemonic('S');
    jBtnSave.setText("Save");
    jBtnSave.setPreferredSize(new Dimension(100,23)); // 30/07
    jBtnSummarySearch.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e) {
    jBtnSummarySearch_actionPerformed(e);
    //the listener for losstype combobox
    jCmbBxSummaryLossType.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    jCmbBxSummaryLossType_itemStateChanged(e);
    //Actioin listener for Save button
    jBtnSave.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    jBtnSave_actionPerformed(e);
    //Actioin listener for Cancel button
    jTxtFldSummaryStreetName.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryStreetName.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryStreetName.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryStreetName.setPreferredSize(new Dimension(100, 20));
    jLblSummaryPostCode.setText("Post Code");
    jLblSummaryPostCode.setForeground(Color.black);
    jLblSummaryPostCode.setPreferredSize(new Dimension(100, 17));
    jLblSummaryPostCode.setFont(new java.awt.Font("SansSerif", 1, 12));
    jChkBxNcbLost.setFont(new java.awt.Font("SansSerif", 1, 12));
    jChkBxNcbLost.setPreferredSize(new Dimension(130, 17));
    jChkBxNcbLost.setText("NCB Lost");
    jLblSummaryDeclineReason.setText("Decline Reason");
    jLblSummaryDeclineReason.setForeground(Color.black);
    jLblSummaryDeclineReason.setPreferredSize(new Dimension(102, 17));
    jLblSummaryDeclineReason.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryTime.setText("Time");
    jLblSummaryTime.setForeground(Color.black);
    jLblSummaryTime.setPreferredSize(new Dimension(35, 17));
    jLblSummaryTime.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCity.setText("Town/City");
    jLblSummaryCity.setForeground(Color.black);
    jLblSummaryCity.setPreferredSize(new Dimension(100, 17));
    jLblSummaryCity.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryDateNotified.setText("Date Notified");
    jLblSummaryDateNotified.setForeground(Color.black);
    jLblSummaryDateNotified.setPreferredSize(new Dimension(102, 17));
    jLblSummaryDateNotified.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryLossDesc.setText("Loss Description");
    jLblSummaryLossDesc.setForeground(Color.black);
    jLblSummaryLossDesc.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossDesc.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCatCode.setText("Catastrophe Code");
    jLblSummaryCatCode.setForeground(Color.black);
    jLblSummaryCatCode.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummarySuburb.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummarySuburb.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummarySuburb.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummarySuburb.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryAmountSaved.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryAmountSaved.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryAmountSaved.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryAmountSaved.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryDateNotified.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryDateNotified.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryDateNotified.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryDateNotified.setPreferredSize(new Dimension(100, 20));
    jLblSummaryCauseType.setText("Cause Type");
    jLblSummaryCauseType.setForeground(Color.black);
    jLblSummaryCauseType.setPreferredSize(new Dimension(102, 17));
    jLblSummaryCauseType.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCompanyName.setText("Company Name");
    jLblSummaryCompanyName.setForeground(Color.black);
    jLblSummaryCompanyName.setPreferredSize(new Dimension(100, 17));
    jLblSummaryCompanyName.setFont(new java.awt.Font("SansSerif", 1, 12));
    jCmbBxSummaryCatCode.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryCatCode.setMinimumSize(new Dimension(225, 25));  // on 21/11
    jCmbBxSummaryCatCode.setPreferredSize(new Dimension(126, 25));
    jRdBtnSummaryPM.setFont(new java.awt.Font("SansSerif", 1, 12));
    jRdBtnSummaryPM.setPreferredSize(new Dimension(40, 17));
    jRdBtnSummaryPM.setText("pm");
    jTxtFldSummaryDeclineReason.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryDeclineReason.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryDeclineReason.setMinimumSize(new Dimension(225, 20));
    jTxtFldSummaryDeclineReason.setPreferredSize(new Dimension(225, 20));
    jChkBxLegal.setPreferredSize(new Dimension(130, 17));
    jChkBxLegal.setText("Legal");
    jChkBxLegal.setActionCommand("jChkBxLegal");
    jChkBxLegal.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPanel2.setBorder(BorderFactory.createEtchedBorder());
    jPanel2.setLayout(gridBagLayout1);
    jPanel1.setLayout(gridBagLayout3);
    jLblSummaryPhone.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryPhone.setForeground(Color.black);
    jLblSummaryPhone.setPreferredSize(new Dimension(100, 17));
    jLblSummaryPhone.setText("Phone");
    jRdBtnSummaryAM.setPreferredSize(new Dimension(40, 17));
    jRdBtnSummaryAM.setText("am");
    jRdBtnSummaryAM.setFont(new java.awt.Font("SansSerif", 1, 12));
    jRdBtnSummaryAM.setSelected(true); // 20/12
    jTxtFldSummaryPostCode.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryPostCode.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryPostCode.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPostCode.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLblSummaryAmountSaved.setText("Amount Saved");
    jLblSummaryAmountSaved.setForeground(Color.black);
    jLblSummaryAmountSaved.setPreferredSize(new Dimension(102, 17));
    jLblSummaryAmountSaved.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPnlSummaryCoy.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPnlSummaryCoy.setBorder(titledBorder4);
    jPnlSummaryCoy.setLayout(gridBagLayout2);
    jLblSummaryStreetName.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryStreetName.setForeground(Color.black);
    jLblSummaryStreetName.setPreferredSize(new Dimension(100, 17));
    jLblSummaryStreetName.setText("Street Name");
    jCmbBxSummaryLossType.setBackground(Color.cyan);
    jCmbBxSummaryLossType.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryLossType.setPreferredSize(new Dimension(225, 26));
    jCmbBxSummaryCauseType.setBackground(Color.cyan);
    jCmbBxSummaryCauseType.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryCauseType.setPreferredSize(new Dimension(225, 26));
    jLblSummaryLossDate.setText("Loss Date");
    jLblSummaryLossDate.setForeground(Color.black);
    jLblSummaryLossDate.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossDate.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtArLossDescription.setLineWrap(true);
    jTxtArLossDescription.setWrapStyleWord(true);
    jTxtArLossDescription.setBackground(Color.cyan);
    jTxtArLossDescription.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtArLossDescription.setBounds(new Rectangle(124, 39, 394, 46));
    jChkBxNoBlameBonus.setPreferredSize(new Dimension(130, 17));
    jChkBxNoBlameBonus.setText("No Blame Bonus ");
    jChkBxNoBlameBonus.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPanel1.setBorder(titledBorder3);
    jPanel1.setBounds(new Rectangle(23, 11, 810, 436));
    jPanel1.add(jLblSummaryCatCode, new GridBagConstraints(0, 6, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jScrPnSummaryLossDesc, new GridBagConstraints(1, 1, 6, 1, 0.9, 0.15
    ,GridBagConstraints.SOUTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jScrPnSummaryLossDesc.getViewport().add(jTxtArLossDescription, null);
    jPanel1.add(jRdBtnSummaryPM, new GridBagConstraints(5, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryDeclineReason, new GridBagConstraints(1, 8, 2, 1, 0.1, 0.1
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossDesc, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.5
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossType, new GridBagConstraints(0, 3, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryCauseType, new GridBagConstraints(0, 4, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryDeclineReason, new GridBagConstraints(0, 8, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossDate, new GridBagConstraints(0, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryTime, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryTime, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 107, 7));
    jPanel1.add(jRdBtnSummaryAM, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryCauseType, new GridBagConstraints(1, 4, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryLossDate, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryDateNotified, new GridBagConstraints(1, 7, 1, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jPanel2, new GridBagConstraints(0, 9, 6, 1, 1.0, 0.1
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxNoBlameBonus, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxLegal, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jBtnSave, new GridBagConstraints(5, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxNcbLost, new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(component1, new GridBagConstraints(1, 0, 1, 1, 0.35, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(component2, new GridBagConstraints(5, 0, 1, 1, 0.35, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryLossType, new GridBagConstraints(1, 3, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryCatCode, new GridBagConstraints(1, 6, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jPnlSummaryCoy, new GridBagConstraints(2, 3, 4, 6, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryPhone, new GridBagConstraints(0, 6, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummarySuburb, new GridBagConstraints(0, 3, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryStreetName, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryCity, new GridBagConstraints(1, 4, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryPostCode, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummarySuburb, new GridBagConstraints(1, 3, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryPostCode, new GridBagConstraints(0, 5, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryPhone, new GridBagConstraints(1, 6, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryCompanyName, new GridBagConstraints(1, 0, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryCompanyName, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryStreetName, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryCity, new GridBagConstraints(0, 4, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryDateNotified, new GridBagConstraints(0, 7, 1, 1, 0.1, 0.05
    ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jBtnSummarySearch, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jTxtFldSummaryLossDate.grabFocus();
    jTxtFldSummaryLossDate.setNextFocusableComponent(jTxtFldSummaryTime);
    jTxtFldSummaryTime.setNextFocusableComponent(jRdBtnSummaryAM);
    jRdBtnSummaryAM.setNextFocusableComponent(jRdBtnSummaryPM);
    jRdBtnSummaryPM.setNextFocusableComponent(jTxtArLossDescription);
    jTxtArLossDescription.setNextFocusableComponent(jCmbBxSummaryLossType);
    jCmbBxSummaryLossType.setNextFocusableComponent(jCmbBxSummaryCauseType);
    jCmbBxSummaryCauseType.setNextFocusableComponent(jBtnSummarySearch);
    jBtnSummarySearch.setNextFocusableComponent(jCmbBxSummaryCatCode);
    jCmbBxSummaryCatCode.setNextFocusableComponent(jTxtFldSummaryDateNotified);
    jTxtFldSummaryDateNotified.setNextFocusableComponent(jTxtFldSummaryDeclineReason);
    jTxtFldSummaryDeclineReason.setNextFocusableComponent(jTxtFldSummaryCompanyName);
    jTxtFldSummaryCompanyName.setNextFocusableComponent(jTxtFldSummaryStreetName);
    jTxtFldSummaryStreetName.setNextFocusableComponent(jTxtFldSummarySuburb);
    jTxtFldSummarySuburb.setNextFocusableComponent(jTxtFldSummaryCity);
    jTxtFldSummaryCity.setNextFocusableComponent(jTxtFldSummaryPostCode);
    jTxtFldSummaryPostCode.setNextFocusableComponent(jTxtFldSummaryPhone);
    jTxtFldSummaryPhone.setNextFocusableComponent(jChkBxNcbLost);
    jChkBxNcbLost.setNextFocusableComponent(jChkBxNoBlameBonus);
    jChkBxNoBlameBonus.setNextFocusableComponent(jChkBxLegal);
    jChkBxLegal.setNextFocusableComponent(jBtnSave);
    jBtnSave.setNextFocusabl                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     &nbs

    the very simple strategy to do is to call removeAllItems() method for the 2nd combox box and then insert the contents. this is because the validate() method is not repeatedly called and so the contents are not updated immediately.

  • How We can restrict the max no of Selections in JList

    Hi,
    How We can restrict the max. no of selections (at random selections) in JList (ex. max No of of selections is 3 in a JList of having 50 items.)
    Thanks for your advise in advance.

    Hello Satyaki De.
    Thank you very much for your suggestion but my Private information is totally apart from this question & I already I have changed each and every information from the question.
    Thanks
    Kamlesh Gujarathi
    [email protected]

  • Dynamically changing size of JList items?

    Hello!
    I'm working on an application which kind of revolves around a JList with a custom ListCellRenderer. Now, it all works rather good as it is, but I want the selected JList item to show more detailed information about the selected value, and thus I need it to be bigger then the not selected items. The thing is that no matter what I do I can't seem to make the JList adopt to the new size of the selected item, which results in only half of the stuff in the selected item being shown.
    Is there any way to do this it would be great! (I bet there is some really simple way which I have simply overlooked.)
    And, fyi: The component returned by getListCellRendererComponent is a JPanel which consists of three JLabels using a GridLayout. The selected component is generally the same, but with an extra row in the GridLayout.
    Any help/suggestions will be greatly appreceated!
    Yours, Jiddo.

    I have tried with a couple of different layout managers, and none of them (except for this one) seems to offer me the layout I need. Also, I have tried making it return different instances depending on if it is selected or not. The non-selected one has only one row in the layout while the selected has two. Here is a screenshot of how it looks:
    http://img211.imageshack.us/img211/2779/jlistes1.jpg
    Yours, Jiddo.

  • Highlighting JList Items

    Hello
    Could anybody let me how to change the color of Few Items of JList. I know how to change the foreground color of an item which is selected. But, I need to show few items of JList in different color.
    Thanks in advance

    please can you tell us where is/are ..., could you able to demostrate your issue, now
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class JListDisabledItemDemo implements ItemListener, Runnable {
        private static final String ITEMS[] = {
            "Black", "Blue", "Green", "Orange", "Purple", "Red", "White", "Yellow"};
        private JList jList;
        private JCheckBox[] checkBoxes;
        private boolean[] enabledFlags;
        @Override
        public void run() {
            JPanel pnlEnablers = new JPanel(new GridLayout(0, 1));
            pnlEnablers.setBorder(BorderFactory.createTitledBorder("Enabled Items"));
            checkBoxes = new JCheckBox[ITEMS.length];
            enabledFlags = new boolean[ITEMS.length];
            for (int i = 0; i < ITEMS.length; i++) {
                checkBoxes[i] = new JCheckBox(ITEMS);
    checkBoxes[i].setSelected(true);
    checkBoxes[i].addItemListener(this);
    enabledFlags[i] = true;
    pnlEnablers.add(checkBoxes[i]);
    jList = new JList(ITEMS);
    jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jList.setSelectionModel(new DisabledItemSelectionModel());
    jList.setCellRenderer(new DisabledItemListCellRenderer());
    jList.addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
    System.out.println("selection");
    JScrollPane scroll = new JScrollPane(jList);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    JFrame f = new JFrame("JList and Colors");
    Container contentPane = f.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(pnlEnablers);
    contentPane.add(scroll);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(240, 280);
    f.setLocationRelativeTo(null);
    UIManager.put("List.background", Color.red);
    UIManager.put("List.selectionBackground", Color.orange);
    UIManager.put("List.selectionForeground", Color.blue);
    UIManager.put("Label.disabledForeground", Color.magenta);
    SwingUtilities.updateComponentTreeUI(f);
    f.setVisible(true);
    @Override
    public void itemStateChanged(ItemEvent event) {
    JCheckBox checkBox = (JCheckBox) event.getSource();
    int index = -1;
    for (int i = 0; i < ITEMS.length; i++) {
    if (ITEMS[i].equals(checkBox.getText())) {
    index = i;
    break;
    if (index != -1) {
    enabledFlags[index] = checkBox.isSelected();
    jList.repaint();
    public static void main(String args[]) {
    SwingUtilities.invokeLater(new JListDisabledItemDemo());
    private class DisabledItemListCellRenderer extends DefaultListCellRenderer {
    private static final long serialVersionUID = 1L;
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (enabledFlags[index]) {
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    Component comp = super.getListCellRendererComponent(list, value, index, false, false);
    comp.setEnabled(false);
    return comp;
    private class DisabledItemSelectionModel extends DefaultListSelectionModel {
    private static final long serialVersionUID = 1L;
    @Override
    public void setSelectionInterval(int index0, int index1) {
    if (enabledFlags[index0]) {
    super.setSelectionInterval(index0, index0);
    } else {
    if (getAnchorSelectionIndex() < index0) {
    for (int i = index0; i < enabledFlags.length; i++) {
    if (enabledFlags[i]) {
    super.setSelectionInterval(i, i);
    return;
    } else {
    for (int i = index0; i >= 0; i--) {
    if (enabledFlags[i]) {
    super.setSelectionInterval(i, i);
    return;

  • Highlight a word within a JList Item

    I would like to highlight a word red within a JList item. For example, a user has a number of words to select from such as can or will. I would like them to select that word and any entries within the list I would like highlighted. I ONLY want the word within a JList item though and not the whole JList item. I know how to do this with a TextField but am having trouble doing this within a JList. Any help would be greatly appreciated.

    Use html syntax to set color/size of a list item. Try this simple example:
    import java.awt.*;
    import javax.swing.*;
    class Testing extends JFrame {
      public Testing() {
        String [] list = {
           "<html><body>Black <font size=15>Black</font> Black",
           "<html><body>Red <font color=red size=10>Red</font> Red ",
           "<html><body>Blue <font color=blue size=5>Blue</font> Blue"
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel(new BorderLayout());
        JList jlist = new JList(list);
        JScrollPane spane = new JScrollPane(jlist);
        panel.add(spane);
        getContentPane().add(panel);
        setSize(200,200);
      public static void main(String[] args){
        new Testing().setVisible(true);
    }

  • Editing Jlist Item Contents....

    hi,
    i want to edit the contents of a Jlist Item.
    any help???
    Manikandan

    in your ListSelectionListener you must check if the event is one of multiple change events. In your case you get one event when the mouse first selects an item and possible more when you move the cursor over the other entries. If you are only interested in the final selection check if e.getValueIsAdjusting() is false.
    // not interested in events if they are not final
    if (e.getValueIsAdjusting())
        return;
    // do what ever you want
    System.out.println(colorList.getSelectedValue());
    ...Hope this helps!

  • Rendering JList items instantly

    hi friends
    I wanna know how to rendering JList items instantly without selecting any item,so the rendering of the item has to be automatically.
    thank you very much

    Well how does the icon change? Normally changes to the data are done by updating the model, in which case the list will get painted automatically.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • How to center JList  items

    Hi,
    I want to center my Jlist item instead of leave them in the left like usual. My List contains pictures and for the beauty of the design it's better to have the image in the center of each cells. How to do it?
    thanks.

    Do you know how to make a JLabel which contains a centred icon? Now make a ListCellRenderer that uses one of those to render your images in the JList.

  • How to save JList items!

    hello,
    i m creating a class that has three JList components.
    My problem is how to save the each JList items into a seperate logfile(ie. text file).

    More info required:
    What are in the JList? Strings? Custom objects?
    Do you know basic file IO?
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    What you will need to do is get the model, ilterate over each element, then write that element out. If the element is a string, then that is easy, just create a FileWriter, and write the string, followed by a new line.
    If it is a custom object, then the task is harder, and you need to decide how that object should be represented.
    If you are after a computer readable view of the model, rather than a human readable, which can easily be read by Java back into a ListModel, then you want to look at XMLEncoder and XMLDecode, or the Serializing Objects tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

Maybe you are looking for

  • File Operations to A Remote system

    Hi, Is it possible to transfer files from my server to a remote machine through the internet. Basically my server is a web service which will be running on a remote machine over the internet. I need to transfer the files received by this service to m

  • Running Product Config Wizard on WFE throws Exception: System.Data.SqlClient.SqlException:

    When I tried to kick off PSConfig on WFE, I receive the following error: Task upgradebootstrap has failed with an unknown exception <o:p></o:p> Exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while

  • Drivers for Windows XP

    Hi, I own a HP Beats Special Edition 15-p030nr Notebook PC . Notebook Info: Processor AMD A8-5545M APU with Radeon(tm) HD Graphics, 1700 Mhz, 4 Core(s), 4 Logical Processor(s) I was planning to install Windows XP on my machine. Can anyone please prov

  • IDOC type for network?

    Any ideas for the IDOC type for network? (CN21 , CN22 transaction)

  • Order of Index and Glossary in Printed Documentation

    In my RoboHelp HTML project, I'm adding an Index and Glossary to the Printed Documentation section layout. I want both files below the Chapter Layout icon. They both will go no further than the first icon above the TOC. The down arrow is grayed out.