Selecting item in Jlist

Hello,
I'm using a JList but when I set, I'm not able to selected any item
of the JList whereas I can when no CellRendere is set ..
Does anyone see an explanation ?
Thanks in advance

Hello,
I'm using a JList but when I set, I'm not able to^^^
a CellRenderer of Course
selected any items
of the JList whereas I can when no CellRenderer is set
Does anyone see an explanation ?
Thanks in advance

Similar Messages

  • Indicate most recently selected item in JList

    When a JList is set for multiple item selection,
    is there any way to visually indicate to the user
    which item has been most recently selected?
    I notice that in a JTable, a coloured border
    gets painted around the cell most recently
    clicked on (this is in addition to any cell
    background colouring which may be done). This would
    be sufficient in my case for a JList, but I
    cannot tell that JList supports this.
    Any suggestions?
    b.c

    Good point. I've just tried the following:
    Implement a custom cell renderer. In the method,
    getListCellRendererComponent(), when the cell
    has focus, add a coloured border to it. If the
    cell does not have focus, make the border null.
    Works beautifully.
    b.c

  • Show (croll-to) selected item in jlist

    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

    I came to know this from one of the postings.
    dbase_list.ensureIndexIsVisible(0);
    should scroll the JList programatically to the top.
    Hope this helps.
    Ranga.

  • Attempting to Get Specific Items Selected from a JList

    Hello all, back again...
    I'm working on a simple interface that can run an SQL query with specific settings, and these settings can be altered by choosing one or multiple options from a JList to the side of the table that displays the results. My problem is, currently, not being able to figure out how to get the accursed thing to tell me what items in the JList are selected!
    I've tried using:
    int multiselect[] = cmbSystems.getSelectedIndices();...but it inevitably returns an array with a size of 1. Frustrating. I know I'm missing something, but I have no idea what. What am I doing wrong? Thanks!
    ~ Matt

    Mystrunner wrote:
    Hmm, okay... give me a bit to figure that out, and I will. :)Sure. Your SSCCE should probably only consist of a JList that prints out the selected items when the selection changes, or something like that. I would bet that you figure out what's going wrong in the process of boiling your code down to the SSCCE.

  • How to delete items selected in a JList?

    Ahoy,
    I hava made a Multiple selection list (two list: one for
    the items that might be selected and another one
    for the selected items). How can I delete the (faultly) selected items in the second list?
    Thanx,
    // create function button
    copy = new JButton( ">>" );
    delete = new JButton ( "<<");
    copy.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
    // place selected values in functionList
    copyList.setListData(
    functionList.getSelectedValues() );     
    delete.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
    // delete selected items from copyList
    );

    You must get the selected item and remove from the model...
    delete.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int si = list.getSelectedIndex(); //get the index of the item selected
    if (si > -1) {   //to validate that be selected
    listModel.removeElementAt(si);  //remove from the listmodel
    modifyTextField.setText("");  
    });in this url you can see a complete sample..
    http://www.esus.com/javaindex/j2se/jdk1.2/javaxswing/atomiccontrols/jlist/addtojlist.html

  • Changing JList non-editable Font color of the selected items

    Hi All,
    I want to change the font color of non-editable JList's selected items which is not clearly visible to user. And I need to change the font color only the selected item in this scenerio.
    Could you please clarify me?
    <img src="file:///C:/DOCUME~1/sgnanasi/LOCALS~1/Temp/moz-screenshot-4.png" alt="" />

    [email protected] wrote:
    ..I want to change the font color of non-editable JList's selected items which is not clearly visible to user. And I need to change the font color only the selected item in this scenerio.Set a custom [cell renderer|http://java.sun.com/javase/6/docs/api/javax/swing/ListCellRenderer.html] *(<- link)* for the JList.

  • Selected item in a JList - Clear selection after mouse click

    Hello:
    I'm developing a Java GUI application which uses some JLists. I've seen that, when an item of the JList is selected and you click the mouse another time in the same selected item, the selection does not "disappear". Now, the only way I know to do this is tho press Control + click in the selected item.
    I would like that, when I click to the selected item of a list, the selection disappears.
    How can I solve that?
    Lots of thanks for your help.

    add a MouseListener to the list
    in mouseReleased (note: Released), get the selected index
    compare to previous selection - if the same, list.clearSelection()
    if you clear the selection, you'll need to reset the 'previous selection' variable

  • JList selected item color?

    Hi guys,
    Does anyone know the color name or the RGB mixture for the light purple color of a selected item in a JList? I want to use this color elsewhere in my program. It is similar to the color of the links here.

    Color clr = UIManager.getColor("List.selectionBackground");

  • Changing background of selected item in JComboBox when Uneditable

    I need to change the color of the items in a JComboBox list based on the values that change at runtime. I have accomplished this by creating and using a class extended from DefaultListCellRenderer.
    The combobox is enabled and uneditable. The problem is that in 1.5 the behavior changed and now the selected item gets a white background that is set by the UI or DefaultJComboBox. I can no longer set the background for the selected item.
    I have tried using the ComBox Editor. Also, the universal option of UIManager.put("ComboBox.background", Color.xxx) will not work since I have multiple boxes with different backgrounds.
    Does anyone no a work around?

    Unless I misread your problem you may find that your use of DefaultListCellRenderer is incorrect. The following snippet of code (using Java 1.5.0_07) will make the combo box red. The unselected items in the dropdown will be magenta and the selected item orange.
    combo.setBackground(Color.red);
    combo.setRenderer(new DefaultListCellRenderer()     {
         public Component getListCellRendererComponent(JList list,
                    Object value,
                    int index,
                    boolean isSelected,
                    boolean cellHasFocus)
                   Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if(isSelected)
                        c.setBackground(Color.ORANGE);
                   else
                        c.setBackground(Color.MAGENTA);
                   return c;
         });

  • Selected item colours

    I have made a long search but could not find out a solution to the following interest, can anyone help me?
    I want to set the background and/or foreground of a selected item in a menu or a tab pane.
    The jList component has 2 properties to do this "selectedBackground" and "selectedForeground" but menus and tab panes apparently not.
    If the developer can not set this colors any other color choosen is in vain cause the colors actually used are very awfull. Surpresingly this colors are not even the system ones (Windows as far as I tried) .
    Am I missing anything? Is there a way to do this?
    Thamk you

    Do a little more research on UI properties. That way you can set the global background/foreground properties for any component. Classes to consider are UIManager and UIDefaults
    ICE

  • JScrollPane: select items using the keyboard

    Hello.
    I would like to select items just using the (keyboard) arrow keys and shift/ctrl.
    I had a JList that behaved as expected, but I put it into a JScrollPane to get the scroll.
    Now arrow keys do scroll the list, but they do not select its items.
    How can I do it?
    Thank you.

    * List_Demo.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class List_Demo extends JFrame {
        public List_Demo() {
            initComponents();
        private void initComponents() {
            setTitle("List Demo");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(400, 300);
            setLocationRelativeTo(null);
            scrollPane = new JScrollPane();
            list = new JList();
            listmodel = new DefaultListModel();
            list.setModel(listmodel);
            toolBar = new JToolBar();
            textField = new JTextField();
            okButton = new JButton();
            list.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    listValueChanged(evt);
            scrollPane.setViewportView(list);
            getContentPane().add(scrollPane, BorderLayout.CENTER);
            toolBar.setFloatable(false);
            textField.setText("textField");
            toolBar.add(textField);
            okButton.setText("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    okButtonActionPerformed(evt);
            toolBar.add(okButton);
            getContentPane().add(toolBar, BorderLayout.NORTH);
            list.requestFocus();
        private void listValueChanged(ListSelectionEvent evt) {
            System.out.println(list.getSelectedIndex());
        private void okButtonActionPerformed(ActionEvent evt) {
            listmodel.addElement(textField.getText());
            list.requestFocus();
        public static void main(String args[]) {  new List_Demo().setVisible(true);   }
        private JButton okButton;
        private JList list;
        private DefaultListModel listmodel ;
        private JScrollPane scrollPane;
        private JTextField textField;
        private JToolBar toolBar;
    }

  • Ctrl-click deselects item in JList

    I have JList with ListSelectionModel.SINGLE_SELECTION
    and I need exactly one item to be ALWAYS selected.
    But when I make ctrl+click on already selected item then
    this item is deselected and isSelectionEmpty() returns true.
    Does anybody knows how to disable this feature?

    One would think the question would be better asked in the Swing section.
    Why don't you use a JComboBox, because it's exactly made for taking a single selection from a list of items.

  • Using checkboxes to select items in a Spark DataGroup/List?

    I have a DataGroup from Catalyst, laid out like a tile list:
    I'd like to do something a bit different, in that I'd like to allow people to multi-select items in the list using those checkboxes instead of the usual command/control-click.
    The checkbox, label and image are in the itemRenderer.  Is there an easy way that I can have that checkbox toggle the selected state of its list item?

    Hi,
    Using the checkbox as a selection is easy enough as all you have to do is add a change event to the checkbox in the renderer and then in the event
    selected=mycheckbox.selected;
    The fun is how to handle the list click event from the checkbox you can stop propagation but if the item is clicked it will reset the selected indices.
    There is a few ways to handle this
    when processing the list don't use the selected indices just use the checkbox value to determine whats selected
    disable the listbox click event so items have to be selected with the checkbox
    or the most complex lots of overriding so that click acts like a ctrl/click and the checkbox/itemclick can toggle each other.
    David

  • Combox Box not displaying selected item

    Below is the code I'm using to try to capture and display the
    selected item from a ComboBox:
    private function
    changeProjectTypeSelection(event:Event):void{
    projectTypeChange.text+=event.currentTarget.selectedItem.cboProjectType
    + " " +
    event.currentTarget.selectedIndex + "\n";
    Then the ComboBox:
    <mx:ComboBox fontSize="12" x="93" y="83" width="110"
    id="cboProjectType" dataProvider="{projectTypeArray}"
    labelField="projectTypeName" selectedIndex="0"
    click="changeProjectTypeSelection(event)"></mx:ComboBox>
    Then the TextInput:
    <mx:TextInput id="projectTypeChange" x="248.95" y="84"
    width="121"/>
    I know there's something wrong with the Actionscript code...
    just haven't figured it out. Any suggestions would be greatly
    appreciated!

    I've almost got it...
    private function
    changeProjectTypeSelection(event:Event):void{
    var i:int;
    for(i=0;i<projectTypeArray.length;i++){
    if(projectTypeArray.getItemAt(i).projectTypeName ==
    event.currentTarget.selectedItem.projectTypeName){
    projectTypeChange.text+=projectTypeArray.getItemAt(i).projectTypeName
    + "\n";
    Alert.show(projectTypeArray.getItemAt(i).projectTypeName +
    "FirstAlert");
    //Alert.show(event.currentTarget.selectedItem.projectTypeName +
    "SecondAlert");
    I just can't seem to be able to reset the value in the
    textInput field. I've tried setting it equal to spaces in several
    places, but it won't change after the first selection. Any ideas?
    Thanks for any suggestions!

  • Getting selected item from combobox itemrenderer and storing in object

    Hi Guys,
    Can anyone help me in this regard. Its very urgent.
    I have a combo box itemrenderer in datagrid column. I want to get the user selected item from the dropdown of the row(s) (User may select values from combo box from multiple rows of datagrid) and corressponding values of all other columns of the rows and store it in an object . Then pass this object to database to update only those rows that user has changed.
    I am able to get the selected item from combo box using "event.currentTarget.selectedItem" and corressponding values of all other columns of the rows using "valueSelect.ID", etc where valueSelect is object which contains data for datagrid. But am stuck up with, how to store the selected item value of the combobox  and corressponding values of all other columns of the rows into an Object ?.
    Can anybody help me with sample to store selected item from combobox and its corressponding values of all other columns into an object which i can send to db...?
    Kindly help me in this regard.
    Thanks,
    Anand.

    Hi!
    Are you using a collection of VO or DTO as the dataprovider of the combobox component?
    If so, have you created some attribute there to control the user's selection in the combobox?
    For instance:
    private var selected:Boolean = false;
    If your solution fits this approach, you may create a new collection that contains just the objects that were selected by the user, it means you can loop through the datagrid's dataprovider and only insert in this new collection those objects that have the attribute "selected" set to true.
    For instance:
    private function getSelectedRecords(datagridDataProvider:ArrayCollection):ArrayCollection
        var newCollection:ArrayCollection = new ArrayCollection();
        for each (var item:Object in datagridDataProvider)
            if (item.selected)
                newCollection.addItem(item)
        return newCollection;
    Afterwards, you may serialize this new collection with your back-end.
    Hope it helps you!
    Cheers,
    @Pablo_Souza

Maybe you are looking for

  • What to do when changes are made and refresh doesn't show the changes?

    I'm new to SCSM and I have created some lists in authoring tool and when I go into console to edit them they are not showing up. Even after refresh. Also creating some new incident views for support groups are not showing up until I restart the Manag

  • Lumia 920 stuck with spinning gears (bricked) afte...

    My phone has been in the spinning gears mode for almost 48 hours. Tried all the steps to reset the phone but to no avail. Anyone has solution to this?

  • R9 270x Multi-monitor flickering.

    I'm using a 24" AOC E2460SD flat panel monitor as my primary pc display. However, from time to time, i extend the monitor to my 50" LED T.V. to watch movies and the like.  However, when i extend the desktop to both monitors to dual screen, my 24" pc

  • Predefined Form

    Hai to All,           Iam using some user defined and predefined form in my module. If i open user defined form its fine and working good. My problem is that i have load some fields in predefined  form so that if i open the form it takes time to open

  • Cisco ISE Version control via HTTPS

    Hi there.  Is it possible to verify the ISE version by Web GUI? If yes. where can I find the version number`?' BR.