Adding JPanels with loops

Okay... not sure what I'm doing wrong but I'm trying to create an array of JPanels, and using a loop to add them to a main panel... It compiles fine, but theres a runtime error "nullPointerException" every time I try to run it and I'm not quite comprehending why...
JPanel[] Cell_Array = new JPanel[100];
JLabel[] Label_Array = new JLabel[100];
     for (int i=0;i<100;i++) {
          Cell_Array.setBackground(Color.black);
          Label_Array[i].setText(" ");
          Cell_Array[i].add(Label_Array[i]);
          Main_Panel.add(Cell_Array[i]);

You created the array but you have not put any panels into the array, so there is a null at every spot in the array.

Similar Messages

  • Scrolling a custom Component (e.g. JPanel) with overridden paint(Graphic g)

    Hi.
    I&#8217;m creating an application for modelling advanced electrical systems in a house. Until now I have focused on the custom canvas using Java2D to draw my model. I can move the model components around, draw lines between them, and so on.
    But now I want to implement a JScrollPane to be able to scroll a large model. I&#8217;m currently using a custom JPanel with a complete override of the paint(Graphic g) method.
    Screen-shot of what I want to scroll:
    http://pchome.grm.hia.no/~aalbre99/ScreenShot.png
    Just adding my custom JPanel to a JScrollPane will obviously not work, since the paint(Graphic g) method for the JPanel would not be used any more, since the JScrollPane now has to analyze which components inside the container (JPanel) to paint.
    So my question is therefore: How do you scroll a custom Component (e.g. JPanel) where the paint(Graphic g) method is totally overridden.
    I believe the I have to paint on a JViewport instructing the JScrollPane my self, but how? Or is there another solution to the problem?
    Thanks in advance for any suggestions.
    Aleksander.

    I�m currently using a custom JPanel with a complete override of the paint(Graphic g) method. Althought this isn't your problem, you should be overriding the paintComponent(..) method, not the paint(..) method.
    But now I want to implement a JScrollPane to be able to scroll a large model.When you create a custom component to do custom painting then you are responsible for determining the preferredSize of the component. So, you need to override the getPreferredSize(...) method to return the preferredSize of your component. Then scrolling will happen automatically when the component is added to a scrollPane.

  • How to add a JPanel with label and border line

    hi,
    I want a Jpanel with label and border line like this.Inside it i need to have components.Is there a resuable component to bring this directly??
    Any solution in this regards.???
    Label-----------------------------------------------------------
    | |
    | |
    | |
    | |
    | |
    |________________________________________ |

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html]How to Use Borders

  • Just updated my iphone. Now I can se I have two? iCloud accounts? One of them appears on my phone, and I have forgotten the password. When I try to add the other account, I get the message that this account is already added, but with the name of the first

    Just updated my iphone. Now I can se I have two! iCloud accounts? One of them appears on my phone, and I have forgotten the password. When I try to add the other account, I get the message that this account is already added, but with the name of the first account where there is no available password. I have tried several times to reset the password, bun I don't get the information I need - I have no access to email. What can I do?

    Hi, thanks for the suggestion. I have tried as you suggested, and when opening the "purchased" apps some have the icloud logo next to them, but I only have "OPEN" against "Find My iPhone". When opening it up, it goes through the same routine; needs to be updated before proceeding, and wouldn't update because I don't have IOS8.
    Anything else I could try, or am I doomed!
    All of your help is much appreciated, thanks

  • Batch Input : Adding component with C002

    Hi all
    I try to add component on a production ordrer with C0O2 but i have problem with the item category 'R' (Variable-size item). In fact, SAP ask me to fill variable-size item data but i can't run this step with batch input.
    For example with the batch input recorder, i obtain :
    SAPLCOKO1 0110 X
         BDC_OKCODE                         /00
         CAUFVD-AUFNR          10001280
    SAPLCOKO1 0115 X
         BDC_OKCODE          =KPU2
    SAPLCOMK 0120 X
         BDC_CURSOR          RESBD-LGORT(23)
         BDC_OKCODE          /00
         FILTER_BOX          NO_FIL
         SORT_BOX          ST_STA
         RESBD-MATNR(23)      SAM6506P00055
         RESBD-MENGE(23)          2
         RESBD-EINHEIT(23)     M
         RESBD-POSTP(23)          R
         RESBD-VORNR(23)          0040
         RCOLS-APLFL(23)          23
         RESBD-WERKS(23)          0200
         RESBD-LGORT(23)          0010
         BDC_SUBSCR          SAPLCOKO1                               0800ORD_HEADER
         BDC_SUBSCR          SAPLCOMK                                0050BUTTONS
         BDC_SUBSCR          SAPLCOMD                                0160SUBSCR_0100
         BDC_CURSOR          RESBD-ROMEI
         RESBD-MATNR          SAM6506P00055
         RESBD-ROMS1          1000
         RESBD-ROMEI          MM
         RESBD-ROKME          M
    Is there other way to fill variable-size item ? Have you got ideas to simulate this step ?
    I don't use FM because i have to fill the field RESBD-VORNR.
    Thanks in advance for your response.
    Patrick.

    In fact the choice that i have made was wrong.
    Adding component with CO02 is possible with ls_params-nobinpt = ''.

  • Reg creation of  value added service with delivery material

    hi
    I want to create the material which is used for the value added service with delivery .do u know the material type for creating the service material other than material type 'dien '. if i use the material type as ' DIEN ' , then i can't create the shipment. in  my scenario , i need to create the shipment. kindly help me in this scenario with the material type & the procedures

    hi
    I want to create the material which is used for the value added service with delivery .do u know the material type for creating the service material other than material type 'dien '. if i use the material type as ' DIEN ' , then i can't create the shipment. in  my scenario , i need to create the shipment. kindly help me in this scenario with the material type & the procedures

  • JPanel with Image just doesn't want to show

    Hello,
    i am trying to create a JPanel with a JLabel to which i assign an ImageIcon, but for some reason the JPanel seems not to appear in my JFrame.
    Here's the code: private void jbInit() throws Exception
        NumberListener numListener = new NumberListener();
        frame = new JFrame();
        frame.setTitle("Error Manager");
        frame.setLayout(new GridBagLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        numberList = new JList(numbers);
        numberList.addListSelectionListener(numListener);
        numberList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane listScroller = new JScrollPane(numberList);
        listScroller.setPreferredSize(new Dimension(250, 80));
        frame.getContentPane().add(listScroller, gbc);
        imgPanel = new JPanel();
        imgPanel.setSize(300, 250);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image img = toolkit.createImage("Somepic.png");
        imgPanel.add(new JLabel(new ImageIcon(img)));
        gbc.gridx = 1;
        gbc.gridy = 0;
        frame.getContentPane().add(imgPanel, gbc);
        frame.pack();
        frame.setVisible(true);
      }

    Sorry forgot to close the code tags...
    private void jbInit() throws Exception
        NumberListener numListener = new NumberListener();
        frame = new JFrame();
        frame.setTitle("Error Manager");
        frame.setLayout(new GridBagLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        numberList = new JList(numbers);
        numberList.addListSelectionListener(numListener);
        numberList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane listScroller = new JScrollPane(numberList);
        listScroller.setPreferredSize(new Dimension(250, 80));
        frame.getContentPane().add(listScroller, gbc);
        imgPanel = new JPanel();
        imgPanel.setSize(300, 250);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image img = toolkit.createImage("1_Alpinweiss_III.png");
        imgPanel.add(new JLabel(new ImageIcon(img)));
        gbc.gridx = 1;
        gbc.gridy = 0;
        frame.getContentPane().add(imgPanel, gbc);
        frame.pack();
        frame.setVisible(true);
      }

  • Popup containing a JPanel with a JComboBox

    I like to get a Popup containing a JPanel with a JComboBox and some other stuff.
    There are two difficulties:
    - it is not possible to use a Combobox with a light weight popup. So I set combobox.LightWeightPopupEnabled(false). Otherwise the combobox popup won't be shown.
    - If the user changes the popups size (see code: this.getSize() returns a different dimension because of a new Frame size). The combobox popups won't be shown proper after a while.
    Does someone know, why it is not possible to use comboboxes with light weight popups?
    Does somebody know, how to fix the size problem?
    I am using JDK 1.4.1 for Windows Systems.
      private Popup getPopup(){
        if (popup != null) {
          hidePopup();
        Point p = this.getLocationOnScreen();
        Dimension inputSize = this.getSize();
        Dimension tableSize = tablePopup.getSize();
        if( ( p.y + tableSize.height ) < screenSize.height) {
          // will fit below input panel
          popup = factory.getPopup( this, tablePopup,
                                    p.x, p.y + (int)inputSize.height );
        } else {
          // need to fit it above input panel
          popup = factory.getPopup( this, tablePopup,
                                    p.x, p.y - (int)tableSize.height );
        return popup;

    Ok, it works proper with Windows L&F. So I replaced
    private PopupFactory factory =  PopupFactory.getSharedInstance();by
    private WindowsPopupFactory factory = new WindowsPopupFactory();

  • My daughter added songs with her I Tunes Card and My credit card was charged, what do I do?

    My daughter added songs with her I tunes card and my credit card was charged, how do I get it off my credit card?

    What process did your daughter use, there is a specific format to redeem an iTunes gift card. The gift card must be redeemed using the Redeem link in the Quick Links on the right side of the iTunes Store in iTunes on a computer or the Redeem button at the bottom of both the iTunes and App Store apps in iOS. Redeeming the gift card then applies the value of the card as an available credit to the user's iTunes account. The credit is used first before any bank card also stored in the account. If the purchases use the entire credit and there is an additional balance due, it will be charged to any bank card stored in the account.

  • I was adding items with the intent of command z 'ing them back to their original when it crashed, autosaved, and my original numbers were lost to the temp numbers plugged in... how can i get back to the previous version? Because it had closed, command z

    I was adding items with the intent of command z 'ing them back to their original when it crashed, autosaved, and my original numbers were lost to the temp numbers plugged in... how can i get back to the previous version? Because it had closed, command z

    Sorry, this happened in CLOUD numbers....

  • Re-write provide statement with loop

    Hello,
    I am a bit confused how to rewrite a provide statement but with loop instead.
    For example, how would the following code be written with 'loop at':
    PROVIDE * FROM P0001
              FROM P0016 BETWEEN '20020401' AND '20061001'
    ENDPROVIDE
    Thanks for your help.

    Data Retrieval from LDB
    1. Create data structures for infotypes.
    INFOTYPES: 0001, "ORG ASSIGNMENT
    0002, "PERSONAL DATA
    0008. "BASIC PAY
    2. Fill data structures with the infotype records.
    Start-of-selection.
    GET PERNR.
    End-0f-selection.
    Read Master Data
    Infotype structures (after GET PERNR) are internal tables loaded with data.
    The infotype records (selected within the period) are processed sequentially by the PROVIDE - ENDPROVIDE loop.
    GET PERNR.
    PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA
    If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif.
    ENDPROVIDE.
    Period-Related Data
    All infotype records are time stamped.
    IT0006 (Address infotype)
    01/01/1990 12/31/9999 present
    Which record to be read depends on the date selection period specified on the
    selection screen. PN/BEGDA PN/ENDDA.
    Current Data
    IT0006 Address - 01/01/1990 12/31/9999 present
    RP-PROVIDE-FROM-LAST retrieves the record which is valid in the data selection period.
    For example, pn/begda = '19990931' pn/endda = '99991231'
    IT0006 subtype 1 is resident address
    RP-PROVIDE-FROM-LAST P0006 1 PN/BEGDA PN/ENDDA.
    hope it will be of help to u.

  • Custom painting on jpanel with scrollable

    i have a jpanel with custom painting. because the painting can be wider than the view of the panel i need to implement scrollbars. i have experimented with implementing scrollable and using scrollpanes but i have no result. i need a hint or a tutorial how this can be done

    ok, that was the key. but perhaps you can help me with two other problems:
    because i dont know how large my panel ( or my scroll-area) has to be, i need to expand it on demand. i tried setpreferredsize for that reason, but nothing happens. i think this method is only for initializing but doesnt seem to function properly at a later point.
    next prop:
    when i scroll my custom panting area the jpanel isnt repainted. i have some difficulties finding the right eventlistener so that i can get scrollbar events (repaint after each move)

  • HR -- adding year with date and month

    Hi all,
    Can any one let me know what is the logic for adding Year with date and month in HR.
    ex: 01.10.2008   from this date it should be 2 years.
    thnks
    joshi.

    Hi
    u can add days to the date directly ....
    if u have the date V_DATE of type sy-datum u can add directly number of days to get disired date ..
    v_date1 =  v_date + 365 .
    hope it helps ..........

  • How to print out a JPanel with its components

    Hello,
    I want to print out a JPanel where several components are placed in. The problem is just that neither the printAll() method nor the print() method works to do so. There's always just a print of the empty JPanel. Is there in general a possibility to print out a JPanel with its components or are I'm on the wrong way ?
    Thanx,
    Findus

    I just posted this link and it works here:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=361445&tstart=0&trange=15

  • My idvd wont play sound in some parts of my i movie project, even though i can hear the sound in imovie. dont get it??? and at the end of my i movie i added pictures with music. it appears as tough there is some kind of ripple effect when i play in idvd??

    my idvd wont play sound in some parts of my i movie project, even though i can hear the sound in imovie. dont get it??? and at the end of my i movie i added pictures with music. it appears as tough there is some kind of ripple effect when i play in idvd??? i dont know why, i did not add anty effect.

    any suggestions

Maybe you are looking for

  • Error in Phone Software Update page ???

    When looking for a software-update for 6131 -> Update over-the-air Step 2/6 says Back-up data ... to memory card ... I might be blind, but I didn't see a backup option on my 6131. Did anyone see? Perhaps it's an option for S60 phones!? Greetings Carz

  • Dynamic Page Orientation in Reports 6i

    I have the following requirement. I need to print a letter that contains an attachment. The letter is two pages long and the page size letter and orientation is portrait. The attachment is legal but the orientation is landscape. So what it essentiall

  • Service Tax on hold acc balance is not transfering when down payment first

    Dear All, My problem is am not able to transfer service tax interim account to final account thru S_AC0_52000644 under below scenario. Scenario 1: Step 1: Down Payment Entry in F-48 Step 2: Invoice booking in FB60/MIRO Step 3: Clear vendor in F-44 St

  • Can we have a ui:tableRowGroup with in  ui:tableRowGroup...?

    can we have a ui:tableRowGroup with in ui:tableRowGroup please help me by providing a code snippet

  • Compatible video cards for k9n6sgm-v

    Hello guys, i need help. i know that the vga test results supplied on the support page of k9n6sgm-v were up to GF7950 only. what i want to know if it can support graphic cards like geforce series 8 or 9, or its ati counterpart. ive read other forums