How to center JList  items

Hi,
I want to center my Jlist item instead of leave them in the left like usual. My List contains pictures and for the beauty of the design it's better to have the image in the center of each cells. How to do it?
thanks.

Do you know how to make a JLabel which contains a centred icon? Now make a ListCellRenderer that uses one of those to render your images in the JList.

Similar Messages

  • How to save JList items!

    hello,
    i m creating a class that has three JList components.
    My problem is how to save the each JList items into a seperate logfile(ie. text file).

    More info required:
    What are in the JList? Strings? Custom objects?
    Do you know basic file IO?
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    What you will need to do is get the model, ilterate over each element, then write that element out. If the element is a string, then that is easy, just create a FileWriter, and write the string, followed by a new line.
    If it is a custom object, then the task is harder, and you need to decide how that object should be represented.
    If you are after a computer readable view of the model, rather than a human readable, which can easily be read by Java back into a ListModel, then you want to look at XMLEncoder and XMLDecode, or the Serializing Objects tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • I don't even know how to center one item in one wiondow. HELP!

    OK, I can't even do the simplest layout in the whole Universe work with Java:
    Centering one component like a button or a label centered vertically and horizontally.
    Can somebody show me how to accomplish what I want with the follwing program?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Sheep000a extends Applet
    implements ActionListener {
        int sheepNum;
        Button button1;
        Panel panel1;
        public void init() {
            panel1 = new Panel();
            panel1.setBackground(new Color(0,255,255));
            setBackground(new Color(0,255,255));
            button1= new Button("Hi, I'm a Java Button. Do you see me?");
            panel1.add(button1);
            add(panel1);
            button1.addActionListener(this);
            resize(500,300);;
            setVisible(true);
        public void actionPerformed(ActionEvent e) {
    }As it is, the button is centered horizontally, but not vertically. I want it centered even when the window is resized.

    panel1.setLayout(new BorderLayout());
    you'd have to read some articles about layout
    management in swingHmm . . . I've browsed through sections on layout. I just can't get things work.
    I cahnged my program to the following per your sugestion:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Sheep000b extends Applet
    implements ActionListener {
        int sheepNum;
        Button button1;
        Panel panel1;
        public void init() {
            panel1 = new Panel();
            panel1.setLayout(new BorderLayout());
            panel1.setBackground(new Color(0,255,255));
            setBackground(new Color(0,255,255));
            button1= new Button("Hi, I'm a Java Button. Do you see me?");
            panel1.add(button1);
    //      panel1.add(button1, BorderLayout.CENTER);
            add(panel1);
            button1.addActionListener(this);
            resize(500,300);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {
    }It compiles but the button is still at the top.
    Changing panel1.add(button1);
    to the one below doesn't make any difference.
    resize(500,300) does not work anymore either.
    Is this my computer specific problem?

  • Rendering JList items instantly

    hi friends
    I wanna know how to rendering JList items instantly without selecting any item,so the rendering of the item has to be automatically.
    thank you very much

    Well how does the icon change? Normally changes to the data are done by updating the model, in which case the list will get painted automatically.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • How to delete the Cost center line item data

    How to delete the cost center line item data of particular cost center and only one cost center is exisiting for that company code.
    Is there any way to delete the line items in that cost center.
    Can data archiving & deleting can help us..........
    does it have any effect over other cost center data....
    any input needed.........
    regards
    rajesh

    Hi,
    i found 2 reports for you:
    1) CO_TOTAL_WRI - Archiving CO Totals Records   
    2) RKCOITW1     - Archiving CO Line Items: Write Program        
    from 2) is a linlk to customize archiv-parameters
    -> start it with transaction se38 / sa38
    A.

  • 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.

  • Profit center line item report

    Hello All,
    A sales order is created with reference to a service order, now when I see Profit center line items, the function area available in Service order is differ from the function area displaying with sales document number in profit center line item report. Can anyone please tell me where could be the problem.
    Full points will be awarded for the answer.
    Thanks & Regards
    Srini

    Hi,
    what SAP release do you have ?
    Normally the derivation of the functional area is made with the following logic:
    1) manually entered
    2) FI-Substitution (calling point 5 or 6 since ERP2004)
    3) cost center
    4) cost element
    Please see also SAP note 106180 of how to correct wrong functional areas in PCA.
    Best regards,
    Andreas

  • Profit center line items KE5Z - order missing - GLPCA-AUFNR

    Hi folks,
    could anybody give me an advice how to arrange that the order will be displayed in the KE5Z report?
    Field GLPCA-AUFNR
    Thanks a lot.
    Regards
    Edited by: Peter Jankech on Jun 4, 2008 1:41 PM

    Sorry for unclear set question.
    I know how to edit a layout.
    The problem is, that the field GLPCA-AUFNR is initial, therefore in KE5Z-Profit center line items the field order is empty.
    Is there any customizing setting or SAP-Note, which ensures that the field GLPCA-AUFNR is filled?
    Thanks

  • How to do Commitment item carryforward (Fund Management) ?

    Dear experts,
    Please guide me how to do commitment item carryforward.
    I've read thought SAP help, it said I need to do commitment item carryforward.
    But I have no idea, what's the transaction code, what parameter to fill in..
    Kindly guide me or send me related document...please....
    [FM Newbie]

    T code : CJCF - Carry Forward Commitment
    Parameters: - Carrying Forward Commitments
    To carry forward a commitment to the first period of the following fiscal year, proceed as follows:
    Choose Accounting ® Controlling ® Cost Center Accounting ® Year-end closing ® Commitment carried forward.
    Enter the relevant cost center(s).
    Select or deselect the following indicators:
    Test run
    If you select Test run, the system carried forward the commitment, but does not update the results.
    Detail lists
    If you activate Detail list, the system displays the results of the commitment carried forward. The results list shows which values were carried forward.
    You should activate the Detail list together with the Test run. This ensures that you can check the results of the test run.
    Reversal
    The Reversal indicator controls whether data that has already been carried forward should be reversed again or not.
    If you have large amounts of data to process, it is advisable to execute the commitment carry-forward using background processing. This means you can process data at times of minimal system usage.
    Choose Program Execute in background.
    SAP help : - Year-End Closing Reports  
    The reports on year-end closing give you an overview of the closing operations (commitment carryforward and budget carryforward) with fiscal year change.
    The reports display totals records. A comparison of the line items transferred to the new fiscal year with the totals is possible using the program (RFFMCFRC) Year-End Closing Data: Totals Records on Line Items
    Features
    ·        Commitments and budget carried forward (RFFMEP1GX)
    This report displays commitment, budget for commitment and budget for a fiscal year that were carried forward to the following year.
    ·        Commitment carried forward in a test run (RFFMEP2GX)
    This report displays commitment belonging to a fiscal year that was carried forward to the following year in a a test run using the Commitment Carryforward
    ·        Preselected budget (RFFMEP3GX)
    This report displays budget for a fiscal year that was determined for the carryforward into the following year with the program RFFMCF25.

  • FM to get Fund/Fund Center/Commitment Item- Item level total (FMBB)

    Hi,
    1. How to get line item level total of of document created in Fund Management with FMBB tcode? Is there a Function Module for the same? The data stored in FMBH/FMBL are period wise.
    2. Is there any way we can change Prepost amount of a FM document on fund/fund center/commitment item level ?

    Hi Naveen,
    check the following tables
    1. FMIFIHD - FM Header table in Fund management
    2. FMIFIIT - FM Line item Table in Fund management
    3. FMIT - Totals table for fund management
    4. FMIA- Actual Line item table for Fund management
    For the second point, i think you need to reverse the origin document and repost it with correct amount. There is no other option.
    BR
    Amitash

  • Dynamically changing size of JList items?

    Hello!
    I'm working on an application which kind of revolves around a JList with a custom ListCellRenderer. Now, it all works rather good as it is, but I want the selected JList item to show more detailed information about the selected value, and thus I need it to be bigger then the not selected items. The thing is that no matter what I do I can't seem to make the JList adopt to the new size of the selected item, which results in only half of the stuff in the selected item being shown.
    Is there any way to do this it would be great! (I bet there is some really simple way which I have simply overlooked.)
    And, fyi: The component returned by getListCellRendererComponent is a JPanel which consists of three JLabels using a GridLayout. The selected component is generally the same, but with an extra row in the GridLayout.
    Any help/suggestions will be greatly appreceated!
    Yours, Jiddo.

    I have tried with a couple of different layout managers, and none of them (except for this one) seems to offer me the layout I need. Also, I have tried making it return different instances depending on if it is selected or not. The non-selected one has only one row in the layout while the selected has two. Here is a screenshot of how it looks:
    http://img211.imageshack.us/img211/2779/jlistes1.jpg
    Yours, Jiddo.

  • Highlighting JList Items

    Hello
    Could anybody let me how to change the color of Few Items of JList. I know how to change the foreground color of an item which is selected. But, I need to show few items of JList in different color.
    Thanks in advance

    please can you tell us where is/are ..., could you able to demostrate your issue, now
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class JListDisabledItemDemo implements ItemListener, Runnable {
        private static final String ITEMS[] = {
            "Black", "Blue", "Green", "Orange", "Purple", "Red", "White", "Yellow"};
        private JList jList;
        private JCheckBox[] checkBoxes;
        private boolean[] enabledFlags;
        @Override
        public void run() {
            JPanel pnlEnablers = new JPanel(new GridLayout(0, 1));
            pnlEnablers.setBorder(BorderFactory.createTitledBorder("Enabled Items"));
            checkBoxes = new JCheckBox[ITEMS.length];
            enabledFlags = new boolean[ITEMS.length];
            for (int i = 0; i < ITEMS.length; i++) {
                checkBoxes[i] = new JCheckBox(ITEMS);
    checkBoxes[i].setSelected(true);
    checkBoxes[i].addItemListener(this);
    enabledFlags[i] = true;
    pnlEnablers.add(checkBoxes[i]);
    jList = new JList(ITEMS);
    jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jList.setSelectionModel(new DisabledItemSelectionModel());
    jList.setCellRenderer(new DisabledItemListCellRenderer());
    jList.addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
    System.out.println("selection");
    JScrollPane scroll = new JScrollPane(jList);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    JFrame f = new JFrame("JList and Colors");
    Container contentPane = f.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(pnlEnablers);
    contentPane.add(scroll);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(240, 280);
    f.setLocationRelativeTo(null);
    UIManager.put("List.background", Color.red);
    UIManager.put("List.selectionBackground", Color.orange);
    UIManager.put("List.selectionForeground", Color.blue);
    UIManager.put("Label.disabledForeground", Color.magenta);
    SwingUtilities.updateComponentTreeUI(f);
    f.setVisible(true);
    @Override
    public void itemStateChanged(ItemEvent event) {
    JCheckBox checkBox = (JCheckBox) event.getSource();
    int index = -1;
    for (int i = 0; i < ITEMS.length; i++) {
    if (ITEMS[i].equals(checkBox.getText())) {
    index = i;
    break;
    if (index != -1) {
    enabledFlags[index] = checkBox.isSelected();
    jList.repaint();
    public static void main(String args[]) {
    SwingUtilities.invokeLater(new JListDisabledItemDemo());
    private class DisabledItemListCellRenderer extends DefaultListCellRenderer {
    private static final long serialVersionUID = 1L;
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (enabledFlags[index]) {
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    Component comp = super.getListCellRendererComponent(list, value, index, false, false);
    comp.setEnabled(false);
    return comp;
    private class DisabledItemSelectionModel extends DefaultListSelectionModel {
    private static final long serialVersionUID = 1L;
    @Override
    public void setSelectionInterval(int index0, int index1) {
    if (enabledFlags[index0]) {
    super.setSelectionInterval(index0, index0);
    } else {
    if (getAnchorSelectionIndex() < index0) {
    for (int i = index0; i < enabledFlags.length; i++) {
    if (enabledFlags[i]) {
    super.setSelectionInterval(i, i);
    return;
    } else {
    for (int i = index0; i >= 0; i--) {
    if (enabledFlags[i]) {
    super.setSelectionInterval(i, i);
    return;

  • How to center menu and add spacing between buttons?

    Here is my site: http://lauraportfolio.hostoi.com/index.html (If you are using Google Chrome you can right click and select "view page source" to see the html of the page)
    See how the menu button are justified the left of the light pink menu bar? How can I put them in the center?
    I would like to know how to center the menu, and then add spacing between the buttons.
    At one point I added spacing between the buttons using CSS padding, but when I did that the last menu button, "Graphics" ran off the pink menu bar and became invisible and all kinds of crazy ugly stuff!
    Below is what I beleive to be all of the CSS styling for the menu:
    #menubar
              width: 900px;
              height: 72px;
              padding: 0;
              background-color: transparent;
              background-image: url(transparentpink.png);
              background-repeat: repeat;
    ul#menu, ul#menu li
    { float: left;
      margin: 0;
      padding: 0;}
    ul#menu li
              list-style: none;
              padding-right: 0px;
              padding-left: 0px;
              margin-right: auto;
              margin-left: auto;
    ul#menu li a
              letter-spacing: 0.1em;
              display: block;
              float: left;
              height: 37px;
              text-align: center;
              color: #f0dbca;
              text-transform: none;
              text-decoration: none;
              background: transparent;
              font-family: bonvenoCF, verdana, Geneva, sans-serif;
              font-size: 150%;
              font-style: normal;
              font-weight: normal;
              font-variant: normal;
              padding-top: 29px;
              padding-right: 26px;
              padding-bottom: 6px;
              padding-left: 26px;
    ul#menu li a:hover, ul#menu li.selected a, ul#menu li.selected a:hover
              color: #F0DBCA;
              background-color: #F1836A;

    PART 1
    So as long as the width of the buttons plus the padding doesn't go over 900px it won't run off the page?
    Right.   The "box model" in CSS works like this:
    width + padding + border = actual visible/rendered width of box
    height + padding + border = actual visible/rendered height of box.
    PART 2
    And do you know how I can center the whole thin instead of it being left-aligned on the menu bar?
    You can't center floated menu items.  The best you can do is make your menu fit the entire width of the container (or as close as you can) as described in PART 1 above. 
    To center your #menu container, use margin:0 auto;
    To center text, use text-align:center on the #menu li a.
    Nancy O.

  • Double click for JList items selection

    I would like to select JList items only by double clicking on them. I can write a mouse listener for detecting double clicks by my own (and handle it afterwards), by please tell me how to turn the default behavior off (selecting items by clicking one time).
    Thanks in advance
    Marek

    I would like to select JList items only by double clicking on them. Well the standard is to select or highlight on a mouseClick or by using the arrow keys on the keyboard.
    Then once you have a selected item you can perform and Action on the item by double clicking or by using the enter key. Remember you should always be able to use either the keyboard or the mouse to perform any given function.
    This posting shows my solution for the above scenario:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=626866

  • Highlight a word within a JList Item

    I would like to highlight a word red within a JList item. For example, a user has a number of words to select from such as can or will. I would like them to select that word and any entries within the list I would like highlighted. I ONLY want the word within a JList item though and not the whole JList item. I know how to do this with a TextField but am having trouble doing this within a JList. Any help would be greatly appreciated.

    Use html syntax to set color/size of a list item. Try this simple example:
    import java.awt.*;
    import javax.swing.*;
    class Testing extends JFrame {
      public Testing() {
        String [] list = {
           "<html><body>Black <font size=15>Black</font> Black",
           "<html><body>Red <font color=red size=10>Red</font> Red ",
           "<html><body>Blue <font color=blue size=5>Blue</font> Blue"
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel(new BorderLayout());
        JList jlist = new JList(list);
        JScrollPane spane = new JScrollPane(jlist);
        panel.add(spane);
        getContentPane().add(panel);
        setSize(200,200);
      public static void main(String[] args){
        new Testing().setVisible(true);
    }

Maybe you are looking for

  • Inconsistency in MB5B Report

    Hi All, I am getting an inconsistency in MB5B report when i am running this report from begining it is  displaying as (01.01.0000 - Date, 000 - Stock, Unit Value, 9100 INR). I have checked this value 9100 in Line item display of stock account, this e

  • Can I transfer data from a PC to a Mac mini from a USB pen drive?

    I currently use a PC using windows vista, I would like to purchase a Mac mini and need to know if it is possible to transfer data from the intuit quickbooks program to the Mac mini? I have the data backed up on a USB pen drive. I wasn't sure if the s

  • Error when downloading adobe reader

    hello, I am trying to download Adobe reader; however, i recieve this error message ERROR 1935. I have tried to change the server and i tried several links but i was not successful. I have windows 8 and I am using google chrome and internet explorer.

  • Zreport for vendor customer details.

    Hi , I have to create a report tto display a vendor and customer details. on screen i have customer code and vendor code with company code and fiscal year. when i select the cust. code plant and year it will show the doc.no ,post. and doc. date,doc t

  • Blury/low res fonts in HD

    I'm adding subtitles and it looks awful, how can I make them better res? (I am from another country and my language isnt perfect) I mean whole video is in 1080p, i ve added text, and i looks fine but when I end editing text it appears as blury and me