JList is not showing up in my Frame

This is a program I wrote for Having images in a List. A custom cellrenderer and a custom listmodel. Somehow the list itself does not show up in my frame.
import java.awt.Component;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
public class ListWithImages extends JFrame {
     public ListWithImages() {
          //          We need a Custom model and a Custom Cell Renderer
          CustomImageListModel customImageListModel = new CustomImageListModel();
          CustomImageListCellRenderer customImageListCellRenderer = new CustomImageListCellRenderer();
          JList jlist = new JList(customImageListModel);
          jlist.setCellRenderer(customImageListCellRenderer);
          jlist.setVisibleRowCount(6);
          getContentPane().add(new JScrollPane(jlist));
          pack();
          setVisible(true);
     public static void main(String args[]) {
          new ListWithImages();
     class CustomImageListModel extends DefaultListModel {
          @Override
          public void addElement(Object arg0) {
               // TODO Auto-generated method stub
     //          Add 10 elements with images
               for (int i = 0; i < 10; i++) {
                    super.addElement(new Object[] { "Item " + i, new ImageIcon("smiley.jpg") });
     class CustomImageListCellRenderer extends JLabel implements ListCellRenderer {
          public CustomImageListCellRenderer() {
               setOpaque(true);
          public Component getListCellRendererComponent(JList jlist, Object obj,
                    int index, boolean isSelected, boolean focus) {
               CustomImageListModel model = (CustomImageListModel) jlist.getModel();
               setText((String) ((Object[]) obj)[0]);
               setIcon((Icon) ((Object[]) obj)[1]);
               if (!isSelected) {
                    setBackground(jlist.getBackground());
                    setForeground(jlist.getForeground());
               } else {
                    setBackground(jlist.getSelectionBackground());
                    setForeground(jlist.getSelectionForeground());
               return this;
}

I try yhis code and the list is displayed. Try using a layout to get a better design
public ListWithImages() {
                this.setLaout(new FlowLayout());
          //          We need a Custom model and a Custom Cell Renderer
          CustomImageListModel customImageListModel = new CustomImageListModel();
          CustomImageListCellRenderer customImageListCellRenderer = new CustomImageListCellRenderer();
          JList jlist = new JList(customImageListModel);
          jlist.setCellRenderer(customImageListCellRenderer);
          jlist.setVisibleRowCount(6);
          getContentPane().add(new JScrollPane(jlist));
          pack();
          setVisible(true);
     }http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html
HTH

Similar Messages

  • My jList won't show up on the frame

    My problem is that I can't see the JList in the scrollPane. I am able to run and compile this frame through JBuilder, however I get this error message:
    java.lang.NullPointerException new JList(helpTopics)
    If I remove the jpanel from the frame and just drop in the scrollPane with the nested jlist on the frame I am then able to see the list and the items in the list. But I'd like to have it on a panel.
    BTW I am calling this frame from another class that contains the main function. Here is my code:
    import java.awt.*;
    import com.borland.jbcl.layout.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    public class NewFrame extends JFrame{
    private final String[] helpTopics = {"Load Cells", "Strain Gages",
    "Op Amps", "RTD", "Wheatstone Bridge"};
    JPanel jPanel1 = new JPanel();
    JList lstTopics = new JList(helpTopics);
    JScrollPane jScrollPane1 = new JScrollPane();
    public NewFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception {
    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.add(lstTopics, null);
    Any help with my problem would greatly reduce my stress factor.
    Thanks.

    You haven't added the panel to the frame from the code you have just posted.

  • Separator is not showing up in the JList that is set in the TextField

    Hi,
    This problem is really weird and I am tired trying to find the problem and so thought i ll ask u guys... i cant see any problem in the code below.. but when i run it the separator that i want if some condition is true it just dsnt come... i did debug it and it does actually go in the if condition but the separator is not showing up... i dont kno y...
    I am pasting the code of the JList renderer SearchListCellRenderer that implements ListCellRenderer.......it has only one method....
    public Component getListCellRendererComponent(JList list, Object value,
                   int     index, boolean isSelected, boolean cellHasFocus) {
              JLabel label = null;
              if (value != null){
                   label = new JLabel();/*(JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
                   isSelected, cellHasFocus);*/
                   if(!anatomySeparator && anatomyMap.containsKey(value.toString().toLowerCase())){
                        label.setVerticalTextPosition(SwingConstants.BOTTOM);
                        label.setPreferredSize(new Dimension(300, 80));
                        label.setText("<html><body>" + "<p style='color:white;'><b>--------------Anatomy--------------</b></p>" + "<p style='color:white;'><b>" + value.toString() + "</b></p></body></html>");
                        anatomySeparator = true;
                        logger.debug("in anatomy");
                   }else if(!diseaseSeparator && diseaseMap.containsKey(value.toString().toLowerCase())){
                        label.setVerticalTextPosition(SwingConstants.BOTTOM);
                        label.setPreferredSize(new Dimension(300, 80));
                        label.setText("<html><body>" + "<p style='color:white;'><b>---------------Diseases----------------</b></p>" + "<p style='color:white;'><b>" + value.toString() + "</b></p></body></html>");
                        diseaseSeparator = true;
                        logger.debug("in disease");
                   }else if(!propSeparator && observationMap.containsKey(value.toString().toLowerCase())){
                        label.setVerticalTextPosition(SwingConstants.BOTTOM);
                        label.setPreferredSize(new Dimension(300, 80));
                        label.setText("<html><body>" + "<p style='color:white;'><b>-----------Observations----------------</b></p>" + "<p style='color:white;'><b>" + value.toString() + "</b></p></body></html>");
                        propSeparator = true;
                        logger.debug("in observation");
                   }else{
                        label.setPreferredSize(new Dimension(300, 30));
                        label.setText("<html><body><p style='color:white;'><b>" + value.toString() + "</b></p></body></html>");
              return label;
    If i see the output the list in the JList is bold also in the condition i have the label size larger so in some values the label is actually large than others... that means it does go in the if condition... but the separator that i have there it just dsnt show up... i dnt kno wat is wrong... can anyone pls help me with this????
    This is how i set the autocopleter text field with the Jlist and its renderer... if that is of some help.....
    JList list = new JList();
    JPopupMenu popup = new JPopupMenu();
    JTextComponent textComp;
    private static final String AUTOCOMPLETER = "AUTOCOMPLETER"; //NOI18N
    public SearchListCellRenderer renderer;
    public AutoCompleter(JTextComponent comp){
    textComp = comp;
    textComp.putClientProperty(AUTOCOMPLETER, this);
    JScrollPane scroll = new JScrollPane(list);
    scroll.setBorder(null);
    list.setFocusable( false );
    list.setBackground(Color.DARK_GRAY);
    list.setForeground(Color.WHITE);
    renderer = new SearchListCellRenderer();
    list.setCellRenderer(renderer);
    scroll.getVerticalScrollBar().setFocusable( false );
    scroll.getHorizontalScrollBar().setFocusable( false );
    popup.setBorder(BorderFactory.createLineBorder(Color.black));
    popup.add(scroll);
    if(textComp instanceof JTextField){
    textComp.registerKeyboardAction(showAction, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), JComponent.WHEN_FOCUSED);
    textComp.getDocument().addDocumentListener(documentListener);
    }else
    textComp.registerKeyboardAction(showAction, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
    textComp.registerKeyboardAction(upAction, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), JComponent.WHEN_FOCUSED);
    textComp.registerKeyboardAction(hidePopupAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
    popup.addPopupMenuListener(new PopupMenuListener(){
    public void popupMenuWillBecomeVisible(PopupMenuEvent e){
    public void popupMenuWillBecomeInvisible(PopupMenuEvent e){
    textComp.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    public void popupMenuCanceled(PopupMenuEvent e){
    list.setRequestFocusEnabled(false);
    }

    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.

  • Color Corrector's Frame Viewer Split Not Showing Up On External Monitor

    Kind've a long title - sorry - but . . . here's my question:
    Why am I not able to see the Frame Viewer's split on my external monitor?
    A further, more detailed explanation of the problem:
    I recently purchased Ripple Training's Color Correction with Andrew Balis. It's very, very imformative and I think will help a lot when it comes time to begin color correcting the feature I'm working on. The section I'm on shows the Frame Viewer tab in the Tool Bench window that presents itself when one opens Color Correction under the Arrange area. In other words, Arrange>Color Correction sets up your windows for color correcting with your Viewer, Canvas, and Tool Bench windows aligned from left to right. When one opens up the 3 Way Color Corrector on a clip and makes a change in the clip, the Frame Viewer tab in the Tool Bench window will show a split screen where on one side you'll have your clip with the color correction you just did, and the other side un-color corrected. Isn't this (split) image supposed to show up in your external monitor just as the images in the Canvas and the Viewer?
    That doesn't seem to be happening on my external monitor.
    I'm not sure if this problem/issue I'm having is related to the muticlipl issue I posted in an earlier thread http://discussions.apple.com/thread.jspa?threadID=1330596&tstart=0
    perhaps.
    Any help on this issue would be greatly appreciated.
    Thanks in advance,
    Javier Calderon

    Ahhh, Shane. So it's as simple as that? So then there's nothing wrong with my setup or my external monitor? FCP's just not designed to show the Tool Bench's Frame Viewer image in your external monitor? Wow . . . Well that answers that then I guess. And you're right . . . that IS indeed kind've lame . . .
    Thanks.
    Javier
    . . . um . . . doesn't that kind've defeat the purpose of proper color correction then (regarding the Tool Bench's Frame Viewer anyway)? If the only place you can see your color corrected Frame Viewer split images is on a monitor that's NOT suited for color correction? Anyway . . . just a thought . . .

  • Picture frame not showing photos

    I sync my IPad with photos in Aperture. Recently I scanned a couple of my old photos and imported them as JPEG in Aperture and synced them with IPad. I can see these photos in the Photo application, but when I select the album with scanned photos in Picture Frame, they dont show up. That is In Settings I can see the album but when I play the Picture Frame these scanned photos do not show up.
    Other photos (non scanned) show up fine.
    Any ideas why Picture Frame is not showing scanned photos?
    TIA

    From Apple:
    "This is a known issue that we are currently investigating."
    Just in case anybody else ever has this problem. Doesn't seem like many people do, however.
    Jeff
    http://itunes.apple.com/us/book/black-beauty/id558712324?mt=11

  • Entire frame of mini-dv video clips do NOT show in the iMovie '11 viewer in playback mode

    I am editing a wedding video in iMovie11 that was recorded on a mini dv tape.  When I move video clips from the event library to the timeline, the entire frame is displayed in the timeline.  However, the entire frame of the video clip does NOT show in the iMovie viewer or when I playback the video.  I exported the video and burned it to a dvd using Toast 11 pro.  The video recorded to the dvd as it was showing in the iMovie viewer... the full frame does not show.  I would certainly appreciate any advice as to how to solve my problem.  THANK YOU!!!

    Is your video shot in 16:9 aspect ratio or 4:3?
    You can go to File/Project Properties and set the aspect ratio for the project.
    When you get a clip that does not match the project's aspect ratio, you use the Rotate, Crop, Ken Burns tool on the middle toolbar to specify how it should be treated.
    FIT will place the entire clip in the movie, and will letterbox (black bars) so that it fits.
    CROP will fill the screen, but will cut off the top and bottom of your frame.

  • After Effects RAM Preview not showing first 50 frames or so - Mac OS

    So I'm on a 2012 iMac, and when i RAM preview,  it plays audio but video does not show until about 50 or 60 frames in, its like a glitch or lag thats started recently, so it makes ram previewing from a certain time a real pain as i then miss the exact part i want and it c matches up with video a second or two later, i can't find any solutions, please help!!

    As Andrew says, Adobe and Apple are working on figuring this bug out. See the known issues section of this page: After Effects good to go with Mac OSX v10.10 (Yosemite)
    If you let the RAM preview loop at the end of its playback and play through again, it should be smooth and issue-free.

  • JList not showing images

    Have raised a thread giving details of the problem in Java2D forum
    JList not showing images
    Have anybody experienced this issue? I face this issue only when i use swingworker and only for small images (few kBs). It works fine for large images (More than 1MB files). I use Win 7.
    Regards,
    Sreram

    One, do you say because i set the model each time, sometimes the list is not getting repainted? I didn't say that. It's just good concurrency practice to only manipulate models on the EDT, particularly when SwingWorker easily allows the break up of loading the images in a background thread and updating the model on the EDT through the publish/process methods.
    Will the splitting up of worker as process chunks be of any use? Again it's just a good habit to get into for concurrency reasons.
    As for your repainting issue, try changing this line
    item.setImage(getImagefromFile(f)); to
    item.setImage(new ImageIcon(getImageFromFile(f)).getImage()); The ImageIcon class uses MediaTracker to synchronously load images (you can use your own if you want). If you're getting your images via the Toolkit.createImage# methods, then the images need to be loaded. Usually what happens is the toolkit image will get loaded when first drawn. The component that's doing the drawing gets repainted as more of the image comes in. But in the case of a JList, that component is the cell renderer pane and it doesn't care about repaint() calls. So changing the above line will insure the images are already loaded and ready to draw when first shown. tjacobs01 post reminded me of this.

  • Key frame values are not showing

    Does anyone know why my key frame values are not showing? How do I get them back?

    See this about showing and hiding columns:
    After Effects Help | General user interface items

  • PE8 does not show MTS still frame as thumbnail in Organizer

    I am importing some MTS footage into organizer but PE8 does not show the still frame as the thumbnail. All clips have a generic film tape Icon instead.  Why? The clips are properly available though.

    Had the same problem. A pain.
    I renamed the clip in the organizer window to something comprehendible (Birthday_cake.MTS!)
    You could export it to some other format (MPEG2) that shows the thumbnail and then import it if you want a longer approach.

  • Frame not showing

    Hi. I have application consisting of several windows (JFrames)...
    I have Login JFrame which after succesfull password entry shows up MainMenu and dispose itself...
    Then MainMenu calls other JFrames, some of them calls other JFrames.
    Problem is with one particular frame. It's not showing it's content. It is blank and doesn't even react to close (X) button. What may be problem? If I call it within a test class ( having only constructor and main class) it works perfect. When I try to run it as part of application it doesn't work as JFrame, only operations are running.
    Any idea why this?

    Problem is with one particular frame. It's not showing it's content. It is blank and doesn't even react to close (X) button. What may be problem?
    If I call it within a test class ( having only constructor and main class) it works perfect. When I try to run it as part of application it doesn't work as
    JFrame, only operations are running."only operations are running."
    if this is a long-running task, you've blocked the EDT, which also handles painting.
    do the 'operations' in a separate thread

  • JList not showing elements

    Hi To all,
    I am trying to get elements in a JList.All the things are going right but in the application it is not showing any data.
    my code is like ...
    JList jlist=new JList();
    while(---code---)
    //some code
    Vector datalist = new Vector();
    String fname=f.getName();
    for(int i=0;(i<datalist.size());i++)
    datalist.add(fname);
    jlist.setListData(datalist);
    System.out.println(datalist);
    it is showing all names in dos prompt through System.out.println()..
    but not through jlist.
    Any help please
    Thanks in advance

    I'm having a problem with JList (it's not showing the
    elements added to the List).
    i've checked the forum, but couldn't found the answer
    to my problem. Any suggestion on the forum search
    keyword?
    here's my code
    public class TestClass extends JFrame{
    public static void main(String args[]){
    JFrame fra = new MyClass();
    fra.show();
    public class MyClass{
    private JList list;
    public MyClass(){
    setSize(400,300);  
    list = new JList();
    JSplitPane split = new
    ew JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    new JScrollPane(tree),
    new JScrollPane(fileList));
    ContentPane c = getContentPane(c);
    c.add(split);
    } // end of constructor
    public populateListAtRunTime(){
    DefaultListModel listModel = new
    ew DefaultListModel();
    listModel.addElement("Testing 1");
    listModel.addElement("Testing 2");
    list = new JList(listModel);/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    With this line you are not changing the
    list you have already added to the SplitPane
    (I think it is already added before this gets
    called, you never show the relationship of this
    method to the constructor...), instead, you are
    creating a new JList which you never add to
    anywhere. Is there a way to instead add elements
    to the JList's data model instead of creating a new
    one? Something like this:
    DefaultTableModel listModel = list.getListModel(); //Or something like it...
    listModel.addElement(//...);
    list.revalidate();
    } // end of myClass (inner class)
    The tree showed up in the split pane
    And i think the list also showed up on the splitpane
    also (except that the element value is not
    there)...any clue on why this is happening?
    sorry again..i know this topic must have been posted
    numerous time, but i'm bad with search term
    keyword..and did not find any result that come close
    to my match
    I tried JList + visible, JList + show, and a few
    other

  • My Flash CS3 document got corrupted and its not showing timeline frames & drawings on stage. How to retrieve it?

    My Flash CS3 document got corrupted when I clicked on the option "Save & Compact".Now its not showing timeline frames & drawings on stage. Can someone please help me by telling how can I retrieve my work..???

    copy your fla.
    rename the copy to a dot rar file and use winrar to repair it.  then unrar to see if you can get a uncorrupted copy.
    otherwise, rename your fla to a zip, unzip it and recover whatever assets you can.
    or if you have a good swf, try a decompiler (like sothink's) to see if you can recreate your fla.
    and, in the future, save versions of your work so you never have to go through this learning experience with flash or any other document creation tool.

  • The system is not showing the UI as soon as i opened the frame

    Hello!
    I am writing an application in that on clicking on the Button another window will open. In that frame 4 buttons must b visible. I was not able to see untill i am pressing twice on the button.
    Can any one tell the reason for that problem.
    Thanks for any help.
    Rajani Kanth.A

    How can i rectify the bug.. It is not showing the buttons which it shld display. After 2 clicks it is showing the buttons. What can be the problem and shld i proceed further. At this point of time i may cant paste the code. Pls do the favour by telling the reason .

  • I want to upload a Banner to my iTunes U page. The banner file has all the requirements like as, kind, size, frame, and etc. Infortunately,  I could not upload the file. It does not show in Provider Page Configuration or the preview.   Someone could help

    I want to upload a Banner to my iTunes U page.
    The banner file has all the requirements like as, kind, size, frame, and etc.
    Infortunately,  I could not upload the file. It does not show in Provider Page Configuration or the preview.
    Someone could help me?

    Sounds like a driver issue. I never tested in bridge, so I could be wrong. But it sounds to me that when you are connected to that screen, your settings are not set to the full resolution of that screen.

Maybe you are looking for