Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:24:42+00:00 2026-06-02T19:24:42+00:00

I have a panel which contains JList. When i add this panel to west

  • 0

I have a panel which contains JList.
When i add this panel to west BorderLayout with one element everything is OK and i see one element in it but if i add new element or clear all element i see no effect.

Can any body suggest any solution?

JPanel class which contains JList

public class FtpPanel extends JPanel{
public JList ftpJList;
public DefaultListModel ftpListModel;

public FtpPanel(String[] list) {
    this.setLayout(new BorderLayout());
    this.setBorder(new EmptyBorder(20, 20, 20, 20));
    this.ftpListModel = new DefaultListModel();
    for(String s : list){
        this.ftpListModel.addElement(s);
    }
    this.ftpJList = new JList(ftpListModel);
    final JScrollPane wsp = new JScrollPane(this.ftpJList);
    wsp.setBorder(new TitledBorder(new WebBorder(),"ftpsrv.itra.de"));
    this.add(wsp, BorderLayout.CENTER);
}

}

FtpTabPanel to which FtpPanel will be added

public class FtpTabPanel extends JPanel{
public FtpPanel ftpPanel;
public FtpTabPanel() {
    createComponents();
    layoutComponents();
    initializeComponents();
}

private void createComponents() {
    ftpPanel = new FtpPanel(new String[]{"You aren't Connected"});
}
private void layoutComponents() {
    setLayout(new BorderLayout());
    add(ftpPanel,   BorderLayout.WEST);
}

}

Add and remove from Jlist

 addFileToJlist(listOfFtpFile ){
   SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if(listOfFtpFile !=null)
                    ftpTabPanel.ftpPanel.ftpListModel.clear();
                    ftpTabPanel.ftpPanel.updateUI();
                    for(String s : listOfFtpFile){
                       ftpTabPanel.ftpPanel.ftpListModel.addElement(s);
                        ftpTabPanel.ftpPanel.ftpWebList.validate();
                        ftpTabPanel.ftpPanel.updateUI();
                    }
                ftpTabPanel.ftpPanel.ftpWebList.revalidate();
                panel.updateUI();
            }
        });
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:24:44+00:00Added an answer on June 2, 2026 at 7:24 pm

    Here is a simple working example (that is almost same as yours but without unnecessary updates):

    public static void main ( String[] args )
    {
        JFrame frame = new JFrame ();
    
        final DefaultListModel model = new DefaultListModel ();
    
        JList list = new JList ( model );
        frame.add ( new JScrollPane ( list ) );
    
        list.addMouseListener ( new MouseAdapter ()
        {
            public void mousePressed ( MouseEvent e )
            {
                model.clear ();
                Random random = new Random ();
                int max = random.nextInt ( 10 );
                for ( int i = 0; i <= max; i++ )
                {
                    model.addElement ( "" + random.nextInt ( 100 ) );
                }
            }
        } );
    
        frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
        frame.setSize ( 200, 400 );
        frame.setLocationRelativeTo ( null );
        frame.setVisible ( true );
    }
    

    And i don’t really see any problems in your example (except unnecessary validation and updateUI calls). Seems that problem is somewhere else…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a panel on an aspx page which contains an UpdatePanel. This panel
I have an update panel which contains a table, to which I add rows
i have a panel (A), which contains 3 other panels (AA, AB, AC). Each
i have a tab-panel which works fine so far, but as soon as i
I have a Panel which contains 20 PictureBox controls. If a user clicks on
I have a JPanel panel which contains a JTree tree . Sometimes the JTree
I have an update panel which contains a few controls, a Place Holder which
Windows 7 and Windows Vista have a Region and Language control panel which contains
I am using Ext.js 4. I have a panel which contains log messages returned
I have a ModalPopupExtender control and a panel which contains a iframe. The ModalPopupExtender's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.