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 6648459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:39:27+00:00 2026-05-26T00:39:27+00:00

I have a List , and in its ListCellRenderer class I put Labels to

  • 0

I have a List , and in its ListCellRenderer class I put Labels to display "Labels" and data values.

The problem is that when there are more than one elements in the List then the Labels are not aligned , they do not have the same width. Although I used the following code but it does not do anything :

public CListCell(boolean displayPhoto, String[] libelles)
    {
        showPhoto = displayPhoto;
        if (displayPhoto)
        {
            setLayout(new BorderLayout());
            addComponent(BorderLayout.WEST, pic);
        }
        else
            setLayout(new GridLayout(1,1));

        labels = new Label[libelles.length];
        lData = new Label[libelles.length+1];

        for (int i=0;i<libelles.length+1;i++)
        {
            lData[i] = new Label("");
            lData[i].setAlignment(Label.LEFT);
            lData[i].getStyle().setMargin(Component.TOP, 1);
            lData[i].getStyle().setMargin(Component.BOTTOM, 1);
            lData[i].getStyle().setPadding(0, 0, 0, 0);
            if (i == libelles.length)
                break;
            labels[i] = new Label(libelles[i]);
            labels[i].setAlignment(Label.LEFT);
            labels[i].getStyle().setMargin(Component.TOP, 1);
            labels[i].getStyle().setMargin(Component.BOTTOM, 1);
            labels[i].getStyle().setPadding(0, 0, 0, 0);
        }
        
        cRow21.addComponent(labels[0]);
        cRow21.addComponent(lData[1]);
        cRow22.addComponent(labels[1]);
        cRow22.addComponent(lData[2]);
        cRow2.addComponent(BorderLayout.WEST, cRow21);
        cRow2.addComponent(BorderLayout.EAST, cRow22);
        cRow1AndRow2.addComponent(lData[0]);
        cRow1AndRow2.addComponent(cRow2);

        if (displayPhoto)
            addComponent(BorderLayout.CENTER, cRow1AndRow2);
        else
            addComponent(cRow1AndRow2);

        focus.setUIID("bandeau_selection_list");

        this.getStyle().setBgPainter(new LigneHorizontalPainter(this, 0));
    }

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
    {
        Content entry = null;
        Image thumb;
        int[] tLibImpayesLength = new int[list.size()];
        int maxDataLength;
        if (value instanceof Content)
            entry = (Content)value;
        if (entry != null)
        {
            if (showPhoto)
            {
                thumb = createThumbnail(entry.getPhoto(), entry.getColumn(4));
                pic.setIcon(thumb);
            }
            lData[0].setText(Formatage.nvl(entry.getColumn(1),"-"));
            lData[1].setText(Formatage.nvl(entry.getColumn(2),"-"));
            lData[2].setText(Formatage.nvl(entry.getColumn(3),"-")); // lData[2] is the Label which displays value at the right side of the Container , the others are at the above,left and do not cause any problem

            tLibImpayesLength[index] = lData[2].getText().length();
        }
        maxDataLength = Formatage.max(tLibImpayesLength);
        if (lData[2].getText().length() < maxDataLength)
        {
            lData[2].setPreferredW(maxDataLength);
        }
        list.repaint();
        return this;
    }

Here is the captured image in runtime :

enter image description here

When we look at the image then we see that the Impayé (Ar) Labels and the remaining value at their right are not aligned. So how to make them vertically aligned , or have the same width ?

  • 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-05-26T00:39:28+00:00Added an answer on May 26, 2026 at 12:39 am

    You didn’t include the way you laid out the components in the code you posted, you also invoked setPreferredW() which effectively sabotages layout so that’s obviously a mistake.

    Generally to implement something like that place both of the left labels in a box layout Y and place it within the CENTER of a border layout. Place the right hand label in the EAST side of that border layout.

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

Sidebar

Related Questions

I have list of MyObject that looks like this: public class MyObject{ public int
I have a list of items like how its listed below, and I'm trying
I have a list of articles, and each article has its own title and
I have a DataGridView with its datasource set to a generic list of custom
I have looped data from mysql, and it's a pretty long list. What's the
i have list of rows that user select and i want to delete them,
i have list of images and on mouse over there is option box shows
Is it possible to have multiple ListCellRenderer's implementation in a single class? Actually I
I have a List<T> that I want to be able to copy to an
I have a list of URLs and I need to display the Google search

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.