Wallowing in JList and ArrayList

Trying to use ArrayList to make the changes in my array a liitle easier to manage. I have 2 Jlists with the same strings in each 1, purpose is for the user to rearrange the strings if need be. Explanation is in the method.
Can any one explain how this could be done or point me to some examples of this kind of procedure.
  private void moveButtonActionPerformed (java.awt.event.ActionEvent evt) {
/* method for taking a selected value in list 1 and replacing the selected value in list 2
** with the selection from list 1 and resorting the array without losing any questions.
** example( selected Q:1 from list 1, Select Q:4 from list 2, Q:1 now becomes Q:4, Q:2 now becomes
**          Q:1, and Q:4 now becomes Q:5 and so on )
// create a new arraylist for easier manipulation of values 
    String[] Questions = QuestionEditor.getQuestionText();
    ArrayList al = new ArrayList();
    jPanel1.removeAll();
// move the Questions array into the array list    
    for(int i = 0; i < Questions.length; i++) { 
         al.add(Questions);
// get the selected value in list 1 and replace the selected value in list2
al.set(jList2.getSelectedIndex(), jList1.getSelectedValue() );
// move the selected value in list 2 down
// no clue as to what to do next!!!
Thanks
Jim

Jim
It seems the way to look at this is in 3 parts, move all the questions from the one selected in the second list down, move all the questions below the one selected in the first list up and then insert the new string into the empty spot.
loop that will move the answers down
for( int x = jList2.getSelectedIndex(); x < Questions.length; x++ ){
        try{ 
          System.out.println( x );
          System.out.println(Questions[x]);
          al.add((x+1), Questions[x] );
        catch(Exception e ){ System.out.println( e ); }

Similar Messages

  • JList and ArrayList

    please is there a way i can use JList to access Element in an ArrayList one at atime

    Create an implementation of a ListModel that is backed with your ArrayList
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ListModel.html
    Good Luck
    Lee

  • Problems JList and DefaultListModel

    Hi!
    I've got a problem with the removing of items from a DefaultListModel.
    Assume this:
    public class ImageList extends JList implements DropTargetListener {
    private DefaultListModel dlm = new DefaultListModel();
    public void setListData(ArrayList al) {
    for(...) {
    //do some stuff here
    dlm.addElement(al.get(i));
    this.setModel(dlm);
    }In the main Frameclass are an instance of ImageList and a JButton for deleting a selected item from the list.
    content of the actionPerfomed-method of JButton:
    DefaultListModel model = (DefaultListModel)customContentPane.imageList.getModel();
    int index = customContentPane.imageList.getSelectedIndex();
    if(index!=-1) {
    imageData.remove(index);
    model.remove(index);
    }I'm developing with JBuilder and JDK 1.3.0_02 and there the removing works fine!
    But with JDK 1.4.1-rc-b19 i'm getting an ArrayIndexOutOfBoundsException when i try to delete the last item. The exceptions says index: 0, size: 0!
    But same code works without any problem with 1.3!!
    Does anybody knows a solution?
    Thanks in advance
    Martin

    Its me again!
    After some debugging i found out, the IndexOutOfBoundsException always gives 'Index: -1' back, although an item IS selected!
    And the imageList.getSelectedIndex() returns the true current selected item and not -1.
    Is it a bug in the JList and the DefaultListModel?

  • Interesting Focus II: JComboBox, 2 JLists and 1 Button

    Hi All,
    Another Interesting Keyboard Focus Question:
    What we want to do?
    Let's say we want to build a JComboBox whose popup contains 2 JLists and a button.
    What we would probably want to do is:
    comboBox.setUI(new MyComboBoxUI());
    MyComboBoxUI will extend BasicComboBoxUI and
    ovveride createPopup to return a BasicComboPopup subclass
    which will add the other JList and JButton.
    (One can argue that this is not a JComboBox anymore, but bare with me)
    Does it work?
    This will work great with the Mouse, but with the Keyboard we face a problem:
    After our popup is displayed, The JComboBox Still Has The Focus - Any UP or DOWN Events are really proccessed by the JComboBox which simulates JList navigation...
    This is happening because the popup is not keyboard-focusable (and so do all of its components)
    Where' s the problem?
    We want to be able to:
    1. Press TAB to navigate thru the 3 components
    2. Press UP and DOWN to navigate the two JLists
    3. Press Space to activate the JButton
    Possible solutions:
    1.
    Don't subclass BasicComboPopup and write a ComboPopup which uses a Focusable JWindow.
    Problem: The JComboBox will lose the focus when the popup opens
    2.
    Simulate all the DOWN/UP/TAB/SPACE events to the popup
    Problem: The components are not focusable, hence there is no indication
    of who is the current focused component
    (Might be solved by surrounding the 'focused' component with a border)
    Your thoughts?
    If you haven't fell asleep by now, you are welcomed to share you ideas, Thanks
    Eyal Katz

    Sorry, I don't understand what you are trying to accomplish. However one line did catch my eye.
    This is happening because the popup is not keyboard-focusable The code in the popupPopup() method in the following post might help:
    http://forum.java.sun.com/thread.jspa?threadID=636842

  • JList and ListModel, can anyone explain the basics?

    Hi
    I have an object A containing a Vector X of objects. I want to display them in a JList. I could always use DefaultListModel and copy the items of the Vector X into the default list model using addElement. But that would create a copy of the information in vector X. That is exactly why one should use a custom list model to ensure that the data is in sync with the GUI .
    I want to add and remove items from the JList, and simultaious add and remove items from the Vector X. Can anyone proviede a samll example of how to do this.
    I have tryed myselfe, but I can not get the JList updated with the changes of the listmodel. I have read the documentation about ListDataListener, but I just don't get it. A small example would realy be appreciated!
    // Mattias

    Yse I have read the tutorial. But I don't understand it.
    Here is a small example program. Can anyone change the code so the list is updated with the canges that obviously take place (as one can see by pressing the "Dump button")
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    class ListTest extends JFrame implements ActionListener , ListDataListener {
        JList list;
        MyListModel myListModel;
        MyDataObject myDataObject;
        ListTest() {
            JPanel p = new JPanel();
            myDataObject = new MyDataObject();
            myListModel = new MyListModel(myDataObject.x);
            list = new JList(myListModel);
            myListModel.addListDataListener(this);
            JScrollPane listScrollPane = new JScrollPane(list);
            listScrollPane.setPreferredSize(new Dimension(200, 100));
            p.add(listScrollPane);
            JButton b1 = new JButton("Add");
            b1.addActionListener(this);
            p.add(b1);
            JButton b2 = new JButton("Remove");
            b2.addActionListener(this);
            p.add(b2);
            JButton b3 = new JButton("Dump");
            b3.addActionListener(this);
            p.add(b3);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(p);
            pack();
            show();
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("Add")) {
                myListModel.addElement(""+ (1+myListModel.getSize()) );
                System.out.println("Added a row to the list");
            if (e.getActionCommand().equals("Remove")) {
                if (myListModel.getSize()>0) {
                    myListModel.remove(myListModel.getSize()-1);
                    System.out.println("Removed last element from the list");
                else {
                    System.out.println("No more elements to remove");
            if (e.getActionCommand().equals("Dump")) {
                System.out.println("\n\nData in the list model:");
                for (int i=0; i<myListModel.getSize() ; i++) {
                    System.out.println(myListModel.getElementAt(i));
                System.out.println("That should be the same as the vector x in the object myDataObject  :");
                for (int i=0; i<myListModel.getSize() ; i++) {
                    System.out.println(myDataObject.x.get(i));
        public void contentsChanged(ListDataEvent e) {
            System.out.println("contentsChanged");
        public void intervalAdded(ListDataEvent e) {
            System.out.println("intervalAdded");
        public void intervalRemoved(ListDataEvent e) {
            System.out.println("intervalRemoved");
        public static void main(String args[]) {
            new ListTest();
    class MyDataObject {
        Vector x;
        MyDataObject() {
            x=new Vector();
            x.addElement("1");
            x.addElement("2");
    class MyListModel extends AbstractListModel {
        Vector v;
        MyListModel(Vector v) {
            this.v=v;
        public void addElement(Object o) {
            v.addElement(o);
        public Object remove(int index) {
            return v.remove(index);
        public Object getElementAt(int index) {
            return v.get(index);
        public int getSize() {
            return v.size();
    </pre>

  • Key pressed in Jlist and selecting the item of key list accordingly

    Hi,
    I have a JList with the items in sorted order.Now I want that if a person presses any key (say K) then the first item starting with K should be selected.Hmmm I can do it by addding a key listener to the list and cheking all the items in the list ,by traversing through the whole lenght of JList and selecting the item if it starts with the character of the key pressed.
    But i was thinking if there is any better way to do that?
    Regards Amin

    see bugid: 4654916 - it does say that the the
    scrolling for the JList should now work with keyboard
    selection.I have the same problem. Thanx for the hint with the bugid. Saw a good workaround there with a simple subclass of JList. Works for me although it is annoying to subclass JList all the time. The bug seems not to be fixed in the 1.4.1 JDK.
    Andreas

  • Consume MouseEvent to prevent JList and JTree from receiving?!

    I have a JTree and a JList where I have made the CellRenderer so that it has a "button" area. When this button is clicked, I want something to happen. This I have achieved just nicely with a MouseListener, as per suggestion from JavaDocs.
    However, the problem is that when a click is deemed to be within the "button", I do not want the tree or list to process it anymore. But doing e.consume(), both on mousePressed or mouseClicked (though it obviously is pressed the JList and JTree themselves listen to) doesn't do jack.
    How can I achieve this functionality?

    da.futt wrote:
    stolsvik wrote:
    Okay, I managed with a hack: It is the order of listeners that's the problem: The ListUI's MouseListener is installed before mine, and hence will get the MouseEvent before me, so it has already processed it when I get it, and hence consuming it makes no difference. No. Normally, listeners are notified latest-registered to earliest-registered. I don't remember seeing an exception to that rule in the core API. well, you are both right (or wrong ;-) - the rule is: the order of listener notification is undefined, it's an implementation detail which listeners must not rely on. "Anecdotical" experience is that AWTListeners are notified first-registered-first-served, while listeners to swing specific events are notified last-registered-first-served. Below is a snippet (formulated in context of SwingX convenience classes, too lazy ...) showing that difference.
    The latter probably stems from hefty c&p of notification by walking the EventListenerList: the earliest code was implemented very near the beginning of Swing when every little drop of assumed performance optimization was squeezed, such as walking from back to front. Using EventListenerList involves lots of code duplication ... so lazy devs as we all are, simply c&p'ed that loop and just changed the concrete event type and method name. More recently, as in the we-use-all-those-nifty-cool-language-features ;-) I've seen more usage of forEach loops (f.i. in beansbinding) so notification is back to first-in-first-served :-)
    Bottom line: don't rely on any sequence - if needed, use an eventBus (or proxy or however it's called) and define the order there. Darryl's suggestion is as close as we can get in Swing (as it's not supported) but not entirely safe: there's no way to get notified when listeners are added/removed and no hook where to plug-in such a bus into the ui-delegate where it would belong.
    Cheers
    Jeanette
    // output
    02.10.2009 14:21:57 org.jdesktop.swingx.event.EventOrderCheck$1 mousePressed
    INFO: first added mouseListener
    02.10.2009 14:21:57 org.jdesktop.swingx.event.EventOrderCheck$2 mousePressed
    INFO: second added mouseListener
    02.10.2009 14:21:58 org.jdesktop.swingx.event.EventOrderCheck$4 valueChanged
    INFO: second added listSelectionListener
    02.10.2009 14:21:58 org.jdesktop.swingx.event.EventOrderCheck$3 valueChanged
    INFO: first added listSelectionListener
    // produced by
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.logging.Logger;
    import javax.swing.JList;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import org.jdesktop.swingx.InteractiveTestCase;
    import org.jdesktop.test.AncientSwingTeam;
    public class EventOrderCheck extends InteractiveTestCase {
        public void interactiveOrderAWTEvent() {
            JList list = new JList(AncientSwingTeam.createNamedColorListModel());
            MouseListener first = new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    LOG.info("first added mouseListener");
            MouseListener second = new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    LOG.info("second added mouseListener");
            list.addMouseListener(first);
            list.addMouseListener(second);
            ListSelectionListener firstSelection = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting()) return;
                    LOG.info("first added listSelectionListener");
            ListSelectionListener secondSelection = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting()) return;
                    LOG.info("second added listSelectionListener");
            list.addListSelectionListener(firstSelection);
            list.addListSelectionListener(secondSelection);
            showWithScrollingInFrame(list, "event order");
        @SuppressWarnings("unused")
        private static final Logger LOG = Logger.getLogger(EventOrderCheck.class
                .getName());
        public static void main(String[] args) {
            EventOrderCheck test = new EventOrderCheck();
            try {
                test.runInteractiveTests();
            } catch (Exception e) {
                e.printStackTrace();
    }

  • LinkedList class and ArrayList class

    Hi everyone,
    What is difference between LinkedList class and ArrayList class ??

    Hi samue!
    If you had typed that question you would have got many answers.anyway
    difference between Linked List and ArrayList
    1.In linked list each element is stored as an object but not in arraylist
    2.Linked list need iterator to go through its contents but not arraylist
    3.reading element from each takes same time but if you want to add or remove element from the arraylist it takes considerable amount of time depending on the index number. in Linkedlist case it takes constant amount of time to add/remove at any index.
    this should be enough guess to know the difference but if u need try goooogle

  • DnD between Jlist and Canvas...

    Is it all possible to drag the list item from JList and drop it inside the Canvas and place a reference (e.g. lsit item name ) at the exact coordinates where the drop is performed?
    Additionally, for the purpose of my project the Canvas already contains an image of a model space and would need to stay in the background all along!
    Please if anyone have any thoughts, recomendations, suggestions post these here.
    Thanks

    Please, is drag and drop possible between JList and Canvas components so that the inserted item from JList is displayed over the image displayed in the Canvas component?

  • JTree, JList and file selection

    I have a file selection JPanel that I'm creating that has a JTree on the left representing folders and a JList on the right that should have the files and folders listed to be able to select. I have two problems at this point. First, and more important, when a folder is selected, the JList doesn't update to the files in the new folder and I don't see what's keeping it from working. Second, when clicking on a folder in the JTree, it drops the folder to the end of the list and then lets you expand it to the other folders, also it shows the whole folder path instead of just the folder name.
    This is still my first venture into JTrees and JLists and I'm still really new at JPanel and anything GUI, so my code may not make the most sense, but right now I'm just trying to get it to work.
    Thank you.
    public class FileSelection extends JFrame{
              Container gcp = getContentPane();
              File dir=new File("c:/");
              private JList fileList;
              JTree tree;
              DefaultMutableTreeNode folders;
              String filePath,selectedFile="", path;
              TreePath selPath;
              FileListPanel fileLP;
              FolderListPanel folderLP;
              JScrollPane listScroller;
              public FileSelection(String name){
                   super(name);
                   gcp.setLayout(new BorderLayout());
                   fileLP = new FileListPanel();
                   folderLP = new FolderListPanel();
                   gcp.add(fileLP, BorderLayout.CENTER);
                   gcp.add(folderLP, BorderLayout.WEST);
                   setVisible(true);
              private class FileListPanel extends JPanel implements ActionListener{
                   public FileListPanel(){
                        final JButton selectItem = new JButton("Select");
                        final JButton cancel = new JButton("Cancel");
                        final JButton changeDir = new JButton("Change Directory");
                        //add buttons
                        add(selectItem);
                        add(changeDir);
                        add(cancel);
                        //instantiate buttons
                        selectItem.setActionCommand("SelectItem");
                        selectItem.addActionListener(this);
                        changeDir.setActionCommand("ChangeDirectory");
                        changeDir.addActionListener(this);
                        cancel.setActionCommand("Cancel");
                        cancel.addActionListener(this);
                        final String[] fileArr=dir.list();
                        fileList = new JList(fileArr);
                        fileList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                        fileList.setLayoutOrientation(JList.VERTICAL_WRAP);
                        fileList.setVisible(true);
                        fileList.setVisibleRowCount(-1);
                        fileList.setSelectedIndex(0);
                        listScroller = new JScrollPane(fileList);
                        listScroller.setPreferredSize(new Dimension(200,200));
                        listScroller.setAlignmentX(LEFT_ALIGNMENT);
                        add(listScroller);
                        MouseListener mouseListener = new MouseAdapter(){
                             public void mouseClicked(MouseEvent e){
                                  if(e.getClickCount()==2){
                                       int itemIndex = fileList.locationToIndex(e.getPoint());
                                       currFile=fileArr[itemIndex];
                                       dispose();
                        fileList.addMouseListener(mouseListener);
                   public void actionPerformed(ActionEvent e){
                        if("SelectItem".equals(e.getActionCommand())){
                             currFile=(String)fileList.getSelectedValue();
                             dispose();
                        }else{
                        if("Cancel".equals(e.getActionCommand())){
                             dispose();
                        }else{
                        if("ChangeDirectory".equals(e.getActionCommand())){
                             ChangeDir cd = new ChangeDir("Select Directory");
                             cd.setSize(new Dimension(300,275));
                             cd.setLocation(500, 225);
              private class FolderListPanel extends JPanel{
                   public FolderListPanel(){
                        String[] files = dir.list();
                        DefaultMutableTreeNode topNode = new DefaultMutableTreeNode("Files");
                        folders = new DefaultMutableTreeNode("C:/");
                        topNode.add(folders);
                        folders = getFolders(dir, folders);
                        tree = new JTree(topNode);
                        tree.setVisible(true);
                        JScrollPane treeScroller = new JScrollPane(tree);
                        treeScroller.setPreferredSize(new Dimension(500,233));
                        treeScroller.setAlignmentX(LEFT_ALIGNMENT);
                        add(treeScroller);
                        MouseListener mouseListener = new MouseAdapter(){
                             public void mouseClicked(MouseEvent e){
                                  try{
                                       if(e.getClickCount()==1){
                                            selPath = tree.getPathForLocation(e.getX(), e.getY());
                                            path=selPath.getLastPathComponent().toString();
                                            dir = new File(path);
                                            TreeNode tn=findNode(folders, path);                    
                                            if(tn!=null){
                                                 folders.add((MutableTreeNode) getTreeNode(dir, (DefaultMutableTreeNode) tn));
                                            tree.updateUI();
                                            final String[] fileArr=dir.list();
                                            fileList = new JList(fileArr);
                                            fileList.updateUI();
                                            listScroller.updateUI();
                                            fileLP = new FileListPanel();
                                  }catch(NullPointerException npe){
                        tree.addMouseListener(mouseListener);
                   public DefaultMutableTreeNode getFolders(File dir, DefaultMutableTreeNode folders){
                        File[] folderList = dir.listFiles();
                        int check=0;
                        for(int x=0;x<folderList.length;x++){
                             if(folderList[x].isDirectory()){
                                  folders.add(new DefaultMutableTreeNode(folderList[x]));               
                        return folders;
                   public TreeNode getTreeNode(File dir, DefaultMutableTreeNode folders){
                        File[] folderList = dir.listFiles();
                        int check=0;
                        for(int x=0;x<folderList.length;x++){
                             if(folderList[x].isDirectory()){
                                  folders.add(new DefaultMutableTreeNode(folderList[x]));               
                        return folders;
                   public TreeNode findNode(DefaultMutableTreeNode folders, String node){
                        Enumeration children = folders.postorderEnumeration();
                        Object current;
                        while(children.hasMoreElements()){
                             current = children.nextElement();
                             if(current.toString().equals(node)){
                                  return (TreeNode)current;
                        return null;
         }

    Wow! I changed the FolderListPanel's mouseListener to:
    tree.addTreeSelectionListener(new TreeSelectionListener(){
                             public void valueChanged(TreeSelectionEvent tse){
                                  DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                                  if(node==null)return;
                                  Object nodeInfo = node.getUserObject();
                                  dir=new File(nodeInfo.toString());
                                  folders.add((MutableTreeNode) getFolders(dir,node));
                        });and it's amazing how much better the tree is!!! But I still don't have the JList part working. I changed the JList and the FileListPanel to public from private, but that didn't change anything.

  • Regarding_Height in JSplitPane in which JList And JTextArea

    Hi All,
    I have JSplitPane in which two components Jlist and JTextArea
    placed . Here when I type the text in JTextArea respective row no
    is appeared in JList.Here my problem is how to set the row hieght
    of both JTextArea and JList to equal size ....
    Can any body have the idea pls help me.
    Thanks in advance

    have you experimented with JTextArea's getRowHeight() and
    JLists's get/setFixedCellHeight()?

  • A TreeMap and ArrayList question

    I am considering using a TreeMap structure with a String as my key and an ArrayList<Record> as my value. After doing some searching and not quite finding the assurance I desired, I am looking for anyone's guidance on my approach. Allow me to briefly explain my situation.
    I am writing a program which reads a entry log and breaks the information into a more usable form (in particular, separated by each individual). I do not know before hand the names of the people I may encounter in the log, nor how many occurances of their name I may find. Also, it is safe to assume that no one person's name is the same for two different people. I wish to be able to call up a person's name and view all records associated with them. I felt the use of a TreeMap would be best in the event that I wish to list out a report with all individuals found, and such a listing would already be in alphabetical order.
    In summation, is my approach of making a TreeMap<String, ArrayList<Record>> an acceptable practice?
    Thank you for your time.

    Puce wrote:
    >
    If there's the slightest chance, OP, that you'll have to do something other than simply look up records by name, consider an embedded DB. If there's the slightest chance that Ron Manager will come along on Monday and say "Good job! Now, can we look up records by date?" or something, consider an embedded DB."Embedded DB" is something different than "in-memory DB" though. An embedded DB is persistent while a in-memory one is not. If you use an embedded DB, you need to synchronize it after restart with your other data sources, and it will use disk space as well. There are use case for embedded DBs and others for in-memory DBs. Hard to say which is the case here, without knowing more.The OP "isn't allowed" to use a database, which almost certainly means he's not allowed to install any more software on the system, eg, MySQL. So an in-process database is the way to go. Whether it's persistent or not is irrelevant. "Embedded" and "in-memory" are not opposites. By "embedded" we really mean in-process. Do you know of any databases which can run in-process but not in-memory? How about in-memory but not in-process? In reality, we're talking about the same products, configured slightly differently.

  • JList and JTree

    Hello,
    I have a list of servers in a JList( is a seperate class) and when i am selecting a server name from the JList i am calling this value in my main class and I am trying to use this selected value from the Jlist to create a new JTree node but the value is not being displayed as a node.
    Any body having ideas as to why?
    Reg,
    suri

    Hello,
    Thanks for ur replies. I have tried the following way but still no results the node is not appearing in the JTree.
    Here logon(this is a listBox class and contains a JList with a list of server names)
    and root1 is the parent .
    DefaultMutableTreeNode new1 = new DefaultMutableTreeNode(logon.getValue(), true);
         int childCnt = root1.getChildCount();
         treeModel.insertNodeInto(new1, root1, childCnt);
    treeModel.reload(new1);
    treeModel.nodeStructureChanged(new1);
    JTree1.revalidate();
    JPanel1.revalidate();
    Any body any ideas .
    Thanks,
    reg,
    suri

  • Arrows in a text field / Common scroll for a jlist and a graphic field

    I am developing a software which requires me to dynamically add arrows from one list entry to another(depending on the users respone) in a jlist.
    Is there any method to do that directly or by means of two parralel fields(one for the list and other for the arrows) controlled by a single scroll????
    Cheers!!!

    I don't understand the question, but read the Swing tutorial on "How to Use Lists" which shows the proper way to add and remove items from a JList:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Problem with a JList and JScrollpane

    Hi,
    Im having a problem with horizontal scrolling in that I have a simple JList inside a panel and a text box below where the user enters text. Now the text box has a width of 15, but the user can type as many characters as they want..Now the Jlist only displays 15 characters, but the horizontal scroller does not come up, instead just displays for example abcdefghijkl... (the three dots in the end)..
    Isnt my scroller supposed to be automatically scrolling when there is more on the line then the screen displays?? I already have this so far..
    scroller = new JScrollPane(dataList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);thanks!

    Try the following code:
    package sample;
    import java.awt.*;
    import javax.swing.*;
    public class MyDialog extends JDialog {
      public static void main( String[] args) {
        new MyDialog().setVisible(true);
      JPanel contentPanel = new JPanel();
      JScrollPane scrollPane = new JScrollPane();
      JList list = new JList( new Object[] {"abcdefghijklmnopqrstuvwxyz", "123456789012345678901234567890"});
      public MyDialog() {
        contentPanel.setLayout(new BorderLayout());
        getContentPane().add(contentPanel);
        contentPanel.add(scrollPane, BorderLayout.CENTER);
        scrollPane.getViewport().add(list, null);   
        setSize( 100,100);
        setLocation( 100,100);
    }Michael

Maybe you are looking for

  • How do I get six family apple devices to be able to use the same iTunes account to make purchases?

    Our family has an iPad, a MacBook Air, 2 iPhones, and 2 iPod touches. I tried to access music in iTunes on my MacBook Air and a message came up that said you can only have 5 devices use the same iTunes account. What can I do to allow us to all use th

  • Clear RAM/temp files on system SSD disk

    Hi! 6 months ago I installed OS X 10.8.5 on a faster SSD disk on my Mac Pro from 2008. PhotoShop and other heavy applications became much faster with the new flash drive, initially. Now, it's even slower than before, for some reason. Can I clear RAM

  • Problems importing application

    Hi, everybody. i'm having some problems importing applications from my dev env to my prod env. it's something very strange because it was working fine 2 weeks ago, but now it's not running. i get into the import page, choose the file and then the pag

  • Why does Firefox keep crashing?

    I have a Mac 10.6.8 and using Firefox browser 31.0.  Firefox has been crashing constantly for about 3 weeks.  Any thoughts on how I can fix this?  Have not changed anything except download updates to Firefox when available. thank you

  • ADF vs OAF

    Hi, I am currently working on OA Framework. I have read about the difference between OAF and ADF. It is pretty easy to get confuse and assume that ADF is the next generation of OAF. I think this assumption is completely wrong, as ADF in no ways relat