How to center the text displayed in a JList

Hi,
The width of the JList display area is wider than the text displayed. I tried to center the text displayed to make it look nicer. I had tried using "setAlignmentX(Component.CENTER_ALIGNMENT)" in my own ListCellRenderer class but did not work. Any idea how to center the text?
Fai.

Yes, I am using JLabels in my renderer and the following is the code:
public class MyCellRenderer extends JLabel implements ListCellRenderer {
     private static final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);
     public MyCellRenderer() {
          setOpaque(true);
          setIconTextGap(12);
     public Component getListCellRendererComponent(
          JList list,
          Object value,
          int index,
          boolean isSelected,
          boolean cellHasFocus)
          String entry = (String)value;
          setText(entry);
          setFont(new Font("Ariel", Font.BOLD, 18));
          setAlignmentX(Component.CENTER_ALIGNMENT);
          if(isSelected) {
               setBackground(HIGHLIGHT_COLOR);
               setForeground(Color.white);
          } else {
               setBackground(Color.white);
               setForeground(Color.black);
          return this;
Can you point out where to implement the centering logic?
Thanks,
Fai.

Similar Messages

  • How to center the text in JLabel without image?

    I need to center the text inside JLabel, how do i do it?
    Also I need some advise, what is the best way to mark a clicked card (I'm making a card game)?

    I found this method that controls that text alignment:you can try few more:
    label.setVerticalAlignment(JLabel.CENTER);    //these two would  center the label contents
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setHorizontalTextPosition(JLabel.CENTER);Thanks!

  • How to influence the text display of key figures in the interarctive DP

    Hello all,
    Does anyone know if there is a possibility (BADI, etc.) to change the text display of key figures (not characteristics!) in a planning book/data view?
    I know that you can define a free text in the data view but still, this is only one fixed text and it cannot be changed.
    Reason for the request: We would like to use the same key figure (and hence, indicate 2 different texts) for two different purposes (in different selections) without having to create a new data view.
    Kind regards,
    Klemens

    if you dont want a new data view and might even go to the extent of creating a user exit for this ... here is an idea
    - just create auxillary KF ( or use spare Temp KF depending on what you want to do with the data in the view) for each of these KF with the text
    lets say you have KF1 and KF2 - create KF1A and KF2A
    Make sure KF1A = KF1 and KF2a = KF2
    Now depending on user you can display KF 1 and KF2 or KF1a and KF2a depending on the user by using macros USER() and ROW_VISIBLE(0)

  • How to edit the text displayed in KM Upload link?

    Hi All,
            I want to edit the text displayed in KM Upload link ie "You can upload a file to the repository from your computer. Click "Show Properties" to assign another name or to change the settings".
    I tried searching for the resource bundle from which the above text is displayed but couldnt find it.
    Can anyone help?
    Thanks in advance.
    Regards,
    Pooja.

    Hi Pooja
    You can find the text in <b>ResourceEditControl**.properties</b> file, which is available under   <i>com.sap.km.cm.ui\lib\km.appl.ui.edit_api\com\sapportals\wcm\control\edit</i>..
    The text is represented by the key <b>txtUploadControl</b>..
    Regards,
    Sandip

  • How to copy the text from textfield to jlist(please help me)..

    hi to all,i am making chat application , in my program user enters ip in the text field to connect to other computer.whenever user wants to send the message ,he has to enter ip in the text field , all i want to do is to copy the ip from text field to jlist , so user does'nt enter same ip every time , he can just select from the jlist . please help me in this ,can u tell me code for that , i would be thankful to u
    Thankyou
    Naresh

    You've asked a lot of questions the last few days. I think its time you do some reading. The Swing tutorial titled "Creating a GUI Using JFC/Swing: has sections on every component and example code of how to use them. You can even download the entire tutorial and all the example from the following link:
    http://java.sun.com/docs/books/tutorial/
    Here's the link specific link to the section on "Using Lists"
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • How to make the text displayed on JLabel verticaly

    As the Titile!
    thanks a lot

    One way is to add the rotated text to an icon, and then add the icon to the label. See other postings at this forum!

  • Does anybody know how to center the text in a sortableheader?

    I am using UIX.

    Of course you shouldn't do so anyway...
    Terminal programs should coexist with all other terminal programs and not try to dominate the screen.
    They should never clear the screen as this would remove output from other programs running in the same terminal.

  • How do i center the text of a JLabel?

    How do i center the text of a JLabel?

    http://java.sun.com/j2se/1.4/docs/api/javax/swing/JLabel.html#setHorizontalTextPosition(int)

  • How do I center the text in full width accordion panel?

    Hello!
    Is it possible to center the text to follow the full width accordion widget?
    When you expand to fill the screen, the text are fixed and doesn't follow the center headline...
    I created a page so you see what I'm talking about:  http://fullwidthissue.businesscatalyst.com/index.html
    Please respond if you know what to do or if it's impossible..
    Thanx

    This believe this can be fixed within the <head> of the document. I had the same problem and it took me a bit to figure this solution.
    Step 1
    Find the <div> ID that muse gives to the content portion of the accordion element. you can find this by using a web browser that lets you inspect the code.
    Step 2 once you have that code replace u6174. with your specific <div> then past this into your <Head> of the muse document. Almost forgot.....Get a general idea of the minimum size around your content this example it was a width of 750px. and change the width accordingly on this code.
    <style>
    #u6174{
    width: 750px;
    padding-left: 0px;
    padding-right: 0px;
    margin-right: auto;
    margin-left: auto;
    border-right-width: 0px;
    border-left-width: 0px; "}
    </style>
    you can see a sample of this here:
    Alain Hunkins
    At the bottom is this solution working.
    Let me know if that helps.

  • Can I center the text in vertical direction in JTextArea

    for example , if the JTextArea is 50 pixels high, and the text 's height is 20 pixels,
    then how can I center the text in vertical direction in this JTextArea which means
    there is a extra space whose height is 15 pixels over and under the text?

    Exactly what are you trying to do?
    JTextAreas are usually in a scroll pane, you add multiple lines ie height can change
    are you going to make it uneditable etc
    if it is just for a display (uneditable), perhaps a 'tall' JTextField might give you the desired effect

  • How to wrap the text in column headers?

    Hi Friends,
    Can anyone please suggest how to wrap the text in column headers of a Java WebDynpro table?
    I believe that caption is the only UI element that a column header can have and it does not allow wrapping of the text.
    My original requirement is as follows,
    In a table I need to dynamically set the width of the columns according to the width configured by the user in some other view. All the columns of the table are dynamically rendered.
    Now what happens is when the user sets the width of the column to a rather low value, say 15 pixels, then the column is displayed like
    Supplier Catalog Name
    Sheila
    Catalog
    Name
    Dropdown
    As you can see it looks rather odd.
    Supplier Catalog Name is the header of the column and I use IWDCaption for header.
    Sheila Catalog Name Dropdown is the value of a particular row at the specified column. I am using a TextView as the TableCellEditor.
    I think what is happening here is that the framework wraps the text in the TextView according to the width specified (15px) and then the column width is extended because it can not accommodate the text (Supplier Catalog Name ) of the column header.
    We are using SAP NetWeaver Development Studio 7.0.12 as the IDE.
    I searched some forums and many people have suggested using scrollable columns but I don't understand how it will help in wrapping the text in a column header.
    Any help would be of great advantage.
    Thanks
    Amit

    Hi Deepti,
    Thanks a lot for the answer but the option that you have specified does not wrap the text. Instead it truncates the text being displayed and only the substring of the text which could be displayed in the given pixels is displayed.
    I need to show the whole text wrapped (Meaning if the width of the column is not sufficient then the text goes into the next line).
    Ayyapparaj,
    Thanks to you too for an helpful answer. It seems that the Netweaver has finally come up with a way to wrap the text in the column headers but as Manoj pointed out, I do not see the property headerTextWrapping  for a table column, Can you please specify which version of netweaver supports it?
    We are using SAP NetWeaver Development Studio 7.0.12 as the IDE.
    Thanks
    Amit Kapoor

  • How to center a text in numbers

    I am having a little bit of a hard time trying to center a text between 3 or more columns.... how can I do that?

    Threre are a few options:
    1) select the three cells and merge them, then enter the text and open the cell formatter and center the text horizonatlly.  NOTE:  merging cells often causes unexpected problems
    2) create a text box and type the text, then format as horizontally centered.  Place the text box over the  cells, set the fill pattern to the same as the cells
    3) create another table to be the header :
    and set the cell width for one cell to be the same as three in the "other" table
    There are porbably more ways than this.  Hopefully one of these will work for you or you will suggest another that works.

  • How to pull the text for InfoObject in APD

    Hi All,
    I have a requirement where in I have to combine the data from 2 InfoObjects using an APD based on some conditions.
    I need to bring in the text for these infoObjects and there attributes too.
    The proposed solution from my side for pulling the text is
    u2022     Getting the text from the text table u2013 this is working fine but the performance is not good.
    u2022     Making a query above the object and taking the output as the APD input. Now, in the query , I have selected the display option u2018key and textu2019 but when I am using this query as input for the APD, I am not getting the text.
    Please let me know how to get the text using the query output and/ or are there any other approach to get the text of an infoObject.
    Thanks & Regards
    Abhi

    Hi,
    It is possible to read the text tables of the infobject, for eg  In material you can use table /BI0/TMATERIAL
    You have to select a Datasource as the 'Database table  and use /BI0/TMATERIAL  as one of the underlying tables and then choose another datasource with /BI0/MMATERIAL as the underlying table.
    Now that you have all the data that is needed you can use the join to connect the above two datasources .Select the join condition (material in this case) and the fields that you would like to be have to the next level from the individual tables that you have selected earlier.
    I guess if you work in this way you might get the results that you are looking forward quite easily without writting code.
    Let me know if it helps.
    Regards
    Ankit

  • How to enlarge the text or characters on web pages permanently

    I need to know how to enlarge the text or characters permanently. I have difficulty reading the characters of each new page. Every time I zoom in to enlarge characters, the new page automatically returns to small characters. Please help.
    Cheng Lin
    [email protected]

    Try one of these extensions:
    *Default FullZoom Level: https://addons.mozilla.org/en-US/firefox/addon/6965
    *NoSquint: https://addons.mozilla.org/en-US/firefox/addon/2592/
    **More NoSquint info: http://urandom.ca/nosquint/
    <br />
    '''Other issues needing your attention'''
    The information submitted with your question indicates that you have out of date plugins with known security and stability issues that should be updated. To see the plugins submitted with your question, click "More system details..." to the right of your original question post.
    *Adobe PDF Plug-In For Firefox and Netscape
    **New Adobe Reader X (version 10) with Protected Mode just released 2010-11-19
    **See: http://www.securityweek.com/adobe-releases-acrobat-reader-x-protected-mode
    *Shockwave Flash 10.0 r42
    *Next Generation Java Plug-in 1.6.0_22 for Mozilla browsers
    **No security issues corrected in version 1.6.0_23, but, according to Oracle/Java, some stability issues resolved.
    #'''Check your plugin versions''': http://www.mozilla.com/en-US/plugincheck/
    #*'''Note: plugin check page does not have information on all plugin versions'''
    #'''Update Adobe Reader (PDF plugin):'''
    #*From within your existing Adobe Reader ('''<u>if you have it already installed</u>'''):
    #**Open the Adobe Reader program from your Programs list
    #**Click Help > Check for Updates
    #**Follow the prompts for updating
    #**If this method works for you, skip the "Download complete installer" section below and proceed to "After the installation" below
    #*Download complete installer ('''if you do <u>NOT</u> have Adobe Reader installed'''):
    #**Use the links below to avoid getting the troublesome "getplus" Adobe Download Manager and other "extras" you may not want
    #**Use Firefox to download and SAVE the installer to your hard drive from the appropriate link below
    #**Click "Save to File"; save to your Desktop (so you can find it)
    #**After download completes, close Firefox
    #**Click the installer you just downloaded and allow the install to continue
    #***Note: Vista and Win7 users may need to right-click the installer and choose "Run as Administrator"
    #**'''<u>Download link</u>''': ftp://ftp.adobe.com/pub/adobe/reader/
    #***Choose your OS
    #***Choose the latest #.x version (example 9.x, for version 9)
    #***Choose the highest number version listed
    #****NOTE: 10.x is the new Adobe Reader X (Windows and Mac only as of this posting)
    #***Choose your language
    #***Download the file
    #***Windows: choose the .exe file; Mac: choose the .dmg file
    #*Using either of the links below will force you to install the "getPlus" Adobe Download Manager. Also be sure to uncheck the McAfee Scanner if you do not want the link forcibly installed on your desktop
    #**''<u>Also see Download link</u>''': http://get.adobe.com/reader/otherversions/
    #**Also see: https://support.mozilla.com/en-US/kb/Using+the+Adobe+Reader+plugin+with+Firefox (do not use the link on this page for downloading; you may get the troublesome "getplus" Adobe Download Manager (Adobe DLM) and other "extras")
    #*After the installation, start Firefox and check your version again.
    #'''Update the [[Managing the Flash plugin|Flash]] plugin''' to the latest version.
    #*Download and SAVE to your Desktop so you can find the installer later
    #*If you do not have the current version, click on the "Player Download Center" link on the "'''Download and information'''" or "'''Download Manual installers'''" below
    #*After download is complete, exit Firefox
    #*Click on the installer you just downloaded and install
    #**Windows 7 and Vista: may need to right-click the installer and choose "Run as Administrator"
    #*Start Firefox and check your version again or test the installation by going back to the download link below
    #*'''Download and information''': http://www.adobe.com/software/flash/about/
    #**Use Firefox to go to the above site to update the Firefox plugin (will also install plugin for most other browsers; except IE)
    #**Use IE to go to the above site to update the IE ActiveX
    #*'''Download Manual installers'''. Note separate links for:
    #**Plugin for Firefox and most other browsers
    #**ActiveX for IE
    #'''Update the [[Java]] plugin''' to the latest version.
    #*Download site: http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)
    #*Also see "Manual Update" in this article: http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates
    #* Removing old versions (if needed): http://www.java.com/en/download/faq/remove_olderversions.xml
    #* Remove multiple Java Console extensions (if needed): http://kb.mozillazine.org
    #*Java Test: http://www.java.com/en/download/help/testvm.xml

  • How to change the text of label dynamically

    Hi all,
    I have done a dynpro program.It requires to implement the dynamically display the label text, for example: there is a label, sometimes, we want to display "Purchase Order" and sometimes we want to display "Sales Order". Can anyone tell me how to change the text of label according to my requirements? thanks in advance!

    Hi Wei,
    AS of now you will not be able to change the Text Field ( Label ) dynamically or at runtime. This is a limitation.Refer to this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/e4/2adbef449911d1949c0000e8353423/frameset.htm
    But, there is a way around.
    You can make a text field Visible / Invisible based on your program logic. So, based on what you want, you can process a module which will take care of that.
    Have a look at these DEMO Code. You can have a good idea to implement the logic.
    DEMO_DYNPRO_MODIFY_SCREEN - Demonstration of Dynamic Screen Modifications
    Thanks,
    Samantak.

Maybe you are looking for