Different Heights for JList Elements

Either the height does not change,Or the size of the full list changes.
Suggestions??
class CustomRenderer extends JLabel implements ListCellRenderer
int newHeight;
int flag=0;
int index;
public CustomRenderer(int newHeight,int resizingRow)
//newHeight to be assigned to tat particular list element
this.newHeight=newHeight;
//Row of List to Resized
this.index=resizingRow;
setOpaque( true );
public Component getListCellRendererComponent(
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
if(index==resizingRow){                           
flag=1;
setText(value.toString());
list.setFixedCellHeight(-1);
Dimension d = getPreferredSize();
d.height = newHeight;
setPreferredSize(d);
else{   
flag=0;
setText(value.toString());
Dimension d = getPreferredSize(newHeight);
setPreferredSize(d);
return this;
public Dimension getPreferredSize() {
if(flag==1){
//Wen clicked on the particular Index, Resize it
Dimension dim = super.getPreferredSize();
return new Dimension(dim.width,newHeight);
else{
//Else Let it be the same size
Dimension dim = super.getPreferredSize();
JOptionPane.showMessageDialog(this,""+super.getPreferredSize());
return new Dimension(dim.width,50);
public Dimension getPreferredSize(int newHeight) {
Dimension dim = super.getPreferredSize();
return new Dimension(dim);
}

try this
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
class Testing extends JFrame
  String[] cities = {"London","Madrid","New York","Rome","Sydney","Toronto","Washington"};
  DefaultListModel listModel = new DefaultListModel();
  JList list = new JList(listModel);
  public Testing()
    setLocation(400,300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    list.setCellRenderer(new MyRenderer());
    for(int x = 0; x < cities.length; x++) listModel.addElement(cities[x]);
    JScrollPane sp = new JScrollPane(list);
    sp.setPreferredSize(new Dimension(100,150));
    getContentPane().add(sp);
    pack();
    list.addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent lse){
        if(lse.getValueIsAdjusting() == false)
          for(int x = 0; x < listModel.size(); x++)
            listModel.setElementAt(listModel.getElementAt(x),x);
  public static void main(String[] args){new Testing().setVisible(true);}
class MyRenderer extends DefaultListCellRenderer
  public Component getListCellRendererComponent(JList list,Object value,
                      int index,boolean isSelected,boolean cellHasFocus)
    JLabel lbl = (JLabel)super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
    if(list.getSelectedIndex() == index) lbl.setPreferredSize(new Dimension(100,75));
    else lbl.setPreferredSize(new Dimension(100,20));
    return lbl;
}

Similar Messages

  • DropDownByIndex - different coloring for contained elements

    Hi community,
    I'd like to have a DropDownByIndex display some of the contained items with a different background and a tooltip.
    I'm pretty sure this is not possible with Web Dynpro as a fine-grained control of the visual representation of the generated ui elements seems to be impossible but maybe there is special or work-around I have not stumbled over yet.
    It is - however - an easy task with JSP, but I'm sick and tired of AbstractPortalComponents... ;-(
    Thanks for your help!
    regards,
    Christian

    Hi Christian,
                    To display tooltip for DropDownByIndex, there is property
    tooltip. 
    For different background, just set the layout property of Container (which contains  the DropDownByIndex- RootUIElementContainer) to GridLayout.
    In the DropDownByIndex properties change cellBackGroundDesign  to your choice.
    regards,
    Siva
    Sorry:I have overlooked the words contained items with  and misunderstood your requirement  
    So I can not give better answer than  Armin
    Edited by: Siva Rama Krushna on Jan 9, 2008 5:42 PM

  • APIs for Adobe Reader to get the x, y co-ords,width,height of all elements (text/image) in a PDF doc

    Hi all,
    I have written a Acrobat plugin using  PDFEdit APIs to extract x, y co-ordinates, width and height of all  elements(objects) in a PDF document.
    Now, I wanted to make the same working on Adobe Reader.I have added the READER_PLUGIN macro enabled in Project settings.
    When I re-compiled the code, I got a bunch of errors saying all PDFEdit APIs are not available under Adobe Reader.
    My  objective is to parse through the entire PDF document and get x, y  co-ordinates, width, height of all PDF objects (especially Image and  Text objects).
    Can anybody help me how to achieve this ?
    Thanks
    Prasanth

    I know that we cannot obtain the PDEContent of a PDF page from Adobe Reader, as PDEContent is modifiable content and as such it cannot be accessible from Adobe Reader.
    Also, as PDFEdit API's does not work for Adobe Reader, we are trying to figure out a way to achieve this for Adobe reader.
    I am curious to know if the COS APIs can help us in this task.
    I tried to read the stream content using PDPageStmGetToken API. I get the data of this format:
    344.88 0 0 91.44 71.882 41.92cm
    Here, as per PDF reference, I am getting only distance from X Axis and distance from Y Axis. But not width and height.
    Can you knidly let us how to get the image attributes (primarly read only attributes like x and y co-ordinates, width and heoght) with Cos APIs.
    Thanks
    Prasanth

  • How can i apply different color for each cell in jlist component?

    hi guys i need your help and sorry if my english is very bad..guys how can i apply different colors for each cell in jlist component? for example for the first cell i want to apply color blue, for the second cell i want red, etc... i need your answer guys tnx..
    Edited by: ryrene on Mar 21, 2010 12:13 AM

    ryrene wrote:
    hi guys i need your help and sorry if my english is very bad.
    ..guys how can i apply different colors for each cell in jlist component? for example for the first cell i want to apply color blue, for the second cell i want red, etc... i need your answer guys tnx..I'll see your tnx, and raise you dve bmbrs & nplm.

  • A quick way to set different color for certain items in JList?

    is there a quick way of setting different color for certain items in JList?

    Either use HTML strings as the values in your JList (quickest, but may not be the most convenient, especially if your model isn't just text), or create your own ListCellRenderer (e.g. extend DefaultListCellRenderer).
    There is no such thing as "list.setItemForeground(int index, Color c)". You'll have to use one of the methods above.

  • BEx:Hierarchies in DIM and FAC are different for Cost Element

    Hi Experts,
    Whenever we execute a report we are getting a warning message as "Hierarchies in DIM and FAC are different for Cost Element", but in report level we are not maintaining hierarchy properties for Cost Element.
    We have executed Master Data tests in RSRV also and still the problem.
    Is any other to do to get rid of this warning message?
    Thanks in Advance.
    Regards,
    RAO.

    Hi all,
    I face the issue like this but with transaction KOAP - Plan settlement
    But, the problem is that, I do not active reconciliation ledger, so I do not maintain any thing relate to reconciation ledger or adjustment posting? I can do transaction "actual settlement"  without error
    So, How this error come to me?
    And how I can fix it?
    Thanks all!

  • How do you subtract different values for specific array elements?

    Hi LabVIEW Community,
    I am new to LabVIEW and Im working on my first application. One of my challenges that I am having problems solving is how to  subtract specific values from specific elements in an array.
    My aplication is to measure the distance between a sensor and a magnet, however the initial distance for each sensor  to magnet is different. I have converted the voltage to a distance using the Math Node for each element and now need to  correct these values by subtracting their individual initial value.
    The source is a 1D array of DBL64  consisting of 32 elements and each of these values needs to have a different value subtracted.
    eg:
    Element 1 - 5.557
    element 2  - 2,34
    element 3 - 7,654  and so on
    I have tried to seperate (index the array) and subtract the values from each element and then combine them again. This has not been effetive. I need to write these values to an .txt file and also use them in another calculation.
    I have attached my attemted sub VI.
    Any advise would be really apprecieated.
    Solved!
    Go to Solution.
    Attachments:
    Sub VI Split Array_Correct Distance.vi ‏36 KB

    You don't need to overthink it. There's a really simple method. Generate an array that contains all your offsets you want.  Then subtract it off.
    It's the same VI with this change:
    Attachments:
    Sub VI Split Array_Correct Distance_LV12_MOD.vi ‏24 KB

  • Determine component height for different platform

    Hi, all
    It just came to me, how can I determine optimal component height for JLabel,JTextField while calling setPreferredSize on different platform? Different screen dpi,fonts,etc. Is there a guide line, so each component will be not too small?
    Thanks,
    Vincent Chen

    But I need to call setPreferredSize to arrange screen display while using flow layout. Under some situation, flow layout is my only choice. Any solution?

  • Panel collection with auto height for different screen resolution

    Hi.
    I created a page using panel collection by default height for 1024 * 768 screen resolution and works fine. When I change the screen resolution to 1152 * 864 then my page layout changes as I can see lot more space at bottom due to fixed height define for panel collection.
    Here my question is how to make height as dynamic for panel collection which can changed based on screen resolution. Usually percentage for height attribute resolve the issue but JDev 11.1.1.4.0 doesn't support percentage its allows only pixel or em.
    Please let me know to resolve this issue.
    Thanks

    If you want a table to occupy 80% of the height of the screen you should be able to do this with assigining % to the various panelStretch facets - like this:
        <af:form id="f1">
          <af:panelStretchLayout id="psl1" topHeight="10%" bottomHeight="10%">
            <f:facet name="bottom">
              <af:spacer width="10" height="1" id="s2"/>
            </f:facet>
            <f:facet name="center">
              <af:panelCollection id="pc1">
                <f:facet name="menus"/>
                <f:facet name="toolbar"/>
                <f:facet name="statusbar"/>
                <af:table var="row" rowBandingInterval="0" id="t1">
                  <af:column sortable="false" headerText="col4" id="c1">
                    <af:outputText value="#{row.col4}" id="ot1"/>
                  </af:column>
                  <af:column sortable="false" headerText="col5" id="c2">
                    <af:outputText value="#{row.col5}" id="ot2"/>
                  </af:column>
                </af:table>
              </af:panelCollection>
            </f:facet>
            <f:facet name="start"/>
            <f:facet name="end"/>
            <f:facet name="top">
              <af:spacer width="10" height="1" id="s1"/>
            </f:facet>
          </af:panelStretchLayout>
        </af:form>

  • Use two different paragraph formats for one element

    Hi,
    I think this is really simple, but I don't get it.
    I have an element with the name "Step" and I have two paragraph formats for this element. Both for numbering.  I use one of these formats to set the numbering back to one, so I can  start with number 1 anywhere I want, so I think there is noch real  context rule for this case. How do I declare this in my EDD? Is it possible to say my EDD that it is possible to use both.
    Thanks.

    Dokuteam,
    In most cases I have seen context rules using the sibling indicator { first } to handle the start of numbering.
    If you want to be able to control restarting of the numbering anywhere, you can add an attribute to the element, like restart = yes | no with "no" being the default value. Then  your context rule would use an attribute indicator similar to
    If [restart = "yes"]
      use PgfFmt1
    Else
      use PgfFmt2
    - Michael

  • How to set the variable height for TileLayout

    Hi,
    I am using TileLayout in  <s:List> component . TileLayout takes the maximum height of the children and draw the same height for rest of the children in all rows. Instead, I want to have all the rows with various heights if their children have different heights.
    I know there is variable height property in <mx:List> component but which is not there in its spark counterpart. Can you please help me with this issue??
    Thanks,
    Bhoja

    The spark TileLayout class lays out all of its elements in equally sized "cells".  Cells of variable sizes is not currently supported.

  • KB15N_No adjustment account found for cost element Message no. K5112

    When I am trying to post Manual Cost Allocation through TC KB15N with the following input data I am getting the following error message and the same could not be posted.  Kindly advise.
    Screen Variant used: 01 SAP Cost Center
    Input Type: List Entry
    Item No.1
    Sender Cost Center : 3402100942
    Cost Element: 6200001
    Amount : 62,201.56
    Receiving Cost Center: 3405100945
    First four digits represent profit center code.  If first four digits are equal the above error is not coming. But posting is needed with different profit centers.
    No adjustment account found for cost element
    Message no. K5112
    Diagnosis
    Neither standard account determination nor the enhanced function found an adjustment account for the reconciliation posting.
    System Response
    No adjustment account could be determined for cost element  in company code SCCL.
    Procedure
    Maintain the standard or enhanced account determination for transaction KAMV. Information on maintenance can be found in the program documentation.
    Execute

    Hi all,
    I face the issue like this but with transaction KOAP - Plan settlement
    But, the problem is that, I do not active reconciliation ledger, so I do not maintain any thing relate to reconciation ledger or adjustment posting? I can do transaction "actual settlement"  without error
    So, How this error come to me?
    And how I can fix it?
    Thanks all!

  • Best App. to Make Buttons, etc. w/Different Looks for 'onmouseover' etc.

    Hello,
    I'm making a simple 6 page site using DW for a class. I want
    the navagational buttons to have some flair. I can't code yet, but
    am learning. I have soo many tools I don't know which to use.
    Flash? PS and Image Ready? Ill. ? The site is my entire grade. The
    class is on DW, which I can do, just wanted to have different
    appearances for onmouseover, onmousedown and other.
    Is Flash the best app. for this?
    TIA

    > Is Flash the best app. for this?
    Not in the real world, no. The best app would be a graphics
    editor, whether
    it be Microsoft Paint, Photoshop Elements, Fireworks,
    Photoshop, Xara, etc.
    Make the button graphics in your graphics editor, and place
    them on the page
    in DW.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Lino 100" <[email protected]> wrote in
    message
    news:fbh18n$aul$[email protected]..
    > Hello,
    >
    > I'm making a simple 6 page site using DW for a class. I
    want the
    > navagational
    > buttons to have some flair. I can't code yet, but am
    learning. I have soo
    > many
    > tools I don't know which to use. Flash? PS and Image
    Ready? Ill. ? The
    > site
    > is my entire grade. The class is on DW, which I can do,
    just wanted to
    > have
    > different appearances for onmouseover, onmousedown and
    other.
    >
    > Is Flash the best app. for this?
    >
    > TIA
    >

  • Different labels for a textview based on component usage

    Hi,
    We are on SAP E-Recruiting EHP5 and we have a requirement wherein the label of a textview in a view needs to be dynamicaly controlled. The candidates personal data page (view VW_PERSONALDATA of component HRRCF_C_PERSONL_DATA_UI) gets displayed both:
    1) When the candidate is signing up on the portal to create his profile
    2) On the application page while the candidate is applying against a particular position
    Now case 1 is a straightforward one. I set the label to a OTR and it just works fine. Case 2 is where the problem occurs. When the candidate applies against a particular position the standard SAP roadmap comes up with the view VW_PERSONALDATA of component HRRCF_C_PERSONL_DATA_UI as its 1st step. So now how can I set a different label for the textview in this particular case coz the navigation happens dynamically through prepare_dynamic_navigation( ). Appreciate your inputs on this one.
    Regards,
    Uday
    Edited by: Uday Mr on Feb 29, 2012 3:36 PM

    Hi Uday,
    Please try to create it dynamically.
    Example:
    METHOD wddomodifyview.
    *-Data declaration
      DATA: root        TYPE REF TO cl_wd_uielement_container,
            page_header TYPE REF TO cl_wd_page_header.
    *-Get reference to Root UI Element Container
      root ?= view->get_element('ROOTUIELEMENTCONTAINER').
    *-Creating page header
      page_header = cl_wd_page_header=>new_page_header( title = 'Page Header' ).
      cl_wd_flow_data=>new_flow_data( element = page_header ).
    *-Add new page header to ROOT Element Container
      root->add_child( page_header ).
    ENDMETHOD.

  • Different layouts for different pages

    hi all,
    i have created a form in which there are 5 output pages but the print preview shows only the first page out of 5.i want to go to the next page.plz help how would i do that.and  i want different layouts for different pages.
    thnks n regards,
    mukesh.

    Hi Mukesh,
    Read these lines which has been given in help.sap.com and also go through the link given below.
    Main Window on Several Draft Pages :
    if you want the pages on which a table with items is printed to have different layouts. Height and position of the main window may differ on the different pages, but the width must remain the same throughout.
    [Main Window|http://help.sap.com/saphelp_nw70/helpdata/en/b1/243fdabeee11d4b633006094192fe3/content.htm]
    Regards,
    Sravanthi

Maybe you are looking for

  • Formulas results outside of row and column axis

    The report has an area of row axis and column axis. This area is where the results from BW are displayed. We have a requirement where we would have to create formulas using the BW Analyzer results of the row axis and column axis and display the resul

  • Vendor return Excise error

    Hi Gurus, While creating the MIGO for subsequent supply Movt. 123 with reference to vendor return122, system is not able to create Excise part 1 entry. Becouse of this reason i am not able to post vendor excise invoice. Gurus can you plz suggest some

  • Sculpture/CC 11

    Can I just voice my frustration at the fact that some of these softsynths don't respond to cc 11 the way ES2 does, as in, hard wired to expression, control of amplitude. Why can't they all be hard wired like that? I get so frustrated with third party

  • CS2 Install with Windows 7

    I'm trying to install CS2 on a new laptop running Windows 7.  The "Installation Location" window tells me it is installing into C:\Program Files (X86)\Adobe but it says that the space available is 0 MB.  I lowered the UAC slider to the bottom of the

  • No "shared" icon on my phone

    In another thread on home sharing someone noted that they have a "Shared" icon which appears under "More" in the iPod app. Nothing like that on my phone. What's up with that? I've updated my phone and computer with the most recent software, and they