Revalidate/validate + repaint to add a number of JTextFields

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class FIFO_MenuBar extends JMenuBar {
String[] prgsItems = new String[] {"Start Simulation", "Reset", "Exit"};
String[] typeItems = new String[] {"FCFS", "HRRN", "PR", "RR", "SJF", "SRTN"};
public JTextField jTxF0[];
int k = 0;
public FIFO_MenuBar () {
JMenu progress = new JMenu("Program to...");
JMenu typemenu = new JMenu("Simulations Types");
ActionListener listen = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand() == "Start Simulation") {
k = Integer.parseInt(JOptionPane.showInputDialog("Enter number of process"));
jTxF0 = new JTextField[k];
JPanel panel = new JPanel();
for (int i = 0; i < jTxF0.length; i++) {
jTxF0[i] = new JTextField(10);
panel.add(jTxF0);
for (int i = 0; i < prgsItems.length; i++) {
JMenuItem item = new JMenuItem(prgsItems[i]);
item.addActionListener(listen);
//System.out.println(item.getActionCommand());
progress.add(item);
progress.insertSeparator(2);
for (int j = 0; j < typeItems.length; j++) {
JMenuItem item = new JMenuItem(typeItems[j]);
item.addActionListener(listen);
typemenu.add(item);
typemenu.insertSeparator(1);
typemenu.insertSeparator(5);
JMenuItem item;
add(progress);
add(typemenu);
public static void main(String s[]) {
JFrame frame = new JFrame("CPU Simulation");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(new FIFO_MenuBar());
frame.pack();
frame.setVisible(true);
No idea why it wouldn't create the number of JTextFields that I want when I go from "Program to..." --> "Start Simulatioin"...
It just wouldn't add the JTextField for me...

you generally don't want anything in main() except to kick off the program
FIFO_MenuBar is a menuBar, so you don't want to be putting your frame code in there,
best to just pass any needed references.
here's your code split into 2 classes with the necessary reference passed to FIFO....
see if you can follow what's happening
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class FIFO_MenuBar extends JMenuBar {
  String[] prgsItems = new String[] {"Start Simulation", "Reset", "Exit"};
  String[] typeItems = new String[] {"FCFS", "HRRN", "PR", "RR", "SJF", "SRTN"};
  public JTextField jTxF0[];
  int k = 0;
  public FIFO_MenuBar (final JPanel panel) {
    JMenu progress = new JMenu("Program to...");
    JMenu typemenu = new JMenu("Simulations Types");
    ActionListener listen = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        if (event.getActionCommand() == "Start Simulation") {
          k = Integer.parseInt(JOptionPane.showInputDialog("Enter number of process"));
          jTxF0 = new JTextField[k];
          //JPanel panel = new JPanel();
          for (int i = 0; i < jTxF0.length; i++) {
            jTxF0[i] = new JTextField(10);
            panel.add(jTxF0);
panel.revalidate();
panel.repaint();
for (int i = 0; i < prgsItems.length; i++) {
JMenuItem item = new JMenuItem(prgsItems[i]);
item.addActionListener(listen);
//System.out.println(item.getActionCommand());
progress.add(item);
progress.insertSeparator(2);
for (int j = 0; j < typeItems.length; j++) {
JMenuItem item = new JMenuItem(typeItems[j]);
item.addActionListener(listen);
typemenu.add(item);
typemenu.insertSeparator(1);
typemenu.insertSeparator(5);
JMenuItem item;
add(progress);
add(typemenu);
class GUI
public void buildGUI()
JPanel framePanel = new JPanel();
framePanel.setPreferredSize(new Dimension(400,300));
JFrame frame = new JFrame("CPU Simulation");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(framePanel);
frame.setJMenuBar(new FIFO_MenuBar(framePanel));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String s[])
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new GUI().buildGUI();

Similar Messages

  • Validate/repaint applet

    Hi,
    I've got a problem with repaint for a japplet
    what i do is removing a jscrollpane to replace it by another one. so i remove the first component and i add a second !
    the problem is that, on the screen, the first one disappears but when i add the second, nothing is visible !!!
    I've tried everything : invalidate,validate,repaint (on the container, on the parent,...)
    the only thing to see the second one is resizing the browser !!!
    have you a solution ???
    Thanks
    Greg

    getContentPane().remove(panelName);
    getContentPane().add("Center",panelName); // assumes BorderLayout
    validate();

  • How do I add a number on my call log to my contacts on the iPhone?

    How do I add a number on my call log to my contacts?
    I browsed through the forum and didn't see this question.
    Thanks in advance

    If I understand the question correctly, you should be able to just touch the blue arrow icon to the right of the entry on the screen. That should take you to an "Info" screen. There you can choose to call the number, text the number, create a new contact, add the number to an existing contact, or share the contact.

  • How do I add a number to my Send Read Receipts for iMessage

    How do i add a number to my Send Read Receipts for iMessage. It says I can add a email just not a number!

    Link phone number and Apple ID with FaceTime and iMessage
    http://support.apple.com/kb/HT5538

  • How do i add a number to my account?

    how do i add my number to my account ?

    What could you mean?
    Do you have an Apple ID of the form "1234" and you want to change it to "12345"?
    Do you have a credit card listed with a digit missing?
    Do you want to add a telephone number to Contacts?
    I cannot imagine what you mean.

  • TS4006 how do I add another number to my icloud?

    I need to locate another phone that is not listed on my icloud how do I add another number?

    hi,you have to sign-in into the icloud setting  on your device with your apple id  to turn on that "FIND MY IPHONE" function....

  • How do I add a number from one field to another then clear out the first field

    In a form I am creating I have a field or a series of fields that have variable numbers in them. I would like to create another set of fields that when I click on a button (or some other method) will add whatever number is placed in another field to that first field.
    For example:
    Text1a is normally a variable field. I have another field (text2a)  that I input another number into. I normally add these two numbers together manually and the total replaces what was in Text1a.
    Text1a = 4, I enter in a 2 in Text2a, so now Text1a will become a 6. I would like to have it so that when I click on a button it automatically adds the two numbers together and then replaces the current number in Text1a with the new total and also clears out the number in Text2a.
    Note: Text1a and Text2a are columns where the next filed down is Text1b and Text2b and so on.
    Can someone please help me on this?
    Bruce

    If you have a nanoSIM that is for your cell provider just activate it and it should set it up.

  • F110 DME payment file: add a number of lead days to posting and value date

    Hello,
    For an Italian company, the DME payment file (F110) needs to be checked and approved by an accountant after it is created. This takes 3 to 4 days after which the file is sent to the bank. The bank will reject the file if the value date  is three days late (date which the bank uses to process the file on). For fiscal reasons the accounting clerks need the have the same posting date as the value date
    I managed to set the value date in the DME files a couple of days later. The setting I used (FBZP -> bank determination -> value date) adds the number of lead days to the value date on the basis of the posting date as defined by the user in F110. For some reason I cannot set it to 0 days, it always adds up 1 day. Is that a normal effect or have I changed the settings in the wrong way?
    I found another setting in customising ("define value date rules") which seems to have the same functionality. In the help function it is said that the setting does not influence the payment program and that the program manages the value date. Is there another setting? Can this problem be solved without the help of a programmer?
    Thank you very much!
    René
    functional consultant
    Edited by: ConsultantSAINT-OBAIN on Apr 8, 2010 10:24 AM

    Here's a section of code that does exactly that:
    CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
      EXPORTING
        CORRECT_OPTION                     = '+'
        DATE                               = G_WORKAREA3-CREATEDON
        FACTORY_CALENDAR_ID                = L_S_PLANT-FACTCAL_ID
      IMPORTING
    *   DATE                               =
       FACTORYDATE                        = L_FCDATE
      EXCEPTIONS
        CALENDAR_BUFFER_NOT_LOADABLE       = 1
        CORRECT_OPTION_INVALID             = 2
        DATE_AFTER_RANGE                   = 3
        DATE_BEFORE_RANGE                  = 4
        DATE_INVALID                       = 5
        FACTORY_CALENDAR_NOT_FOUND         = 6
        OTHERS                             = 7.
      L_FCDATE = L_FCDATE + L_S_ZLEAD-/BIC/ZLEAD.
      CALL FUNCTION 'FACTORYDATE_CONVERT_TO_DATE'
        EXPORTING
          FACTORYDATE                  = L_FCDATE
          FACTORY_CALENDAR_ID          = L_S_PLANT-FACTCAL_ID
        IMPORTING
          DATE                         = L_DATE
        EXCEPTIONS
          CALENDAR_BUFFER_NOT_LOADABLE = 1
          FACTORYDATE_AFTER_RANGE      = 2
          FACTORYDATE_BEFORE_RANGE     = 3
          FACTORYDATE_INVALID          = 4
          FACTORY_CALENDAR_ID_MISSING  = 5
          FACTORY_CALENDAR_NOT_FOUND   = 6
          OTHERS                       = 7.
    * result value of the routine
      RESULT = L_DATE.

  • IMessage not working. Can't add mobile number!?

    I had never use IMessage before, ever. Only a few days ago did I turn on iMessage which then it said "waiting for activation". I then texted a friend and it was an iMessage BUT she said it was coming from my email. This is really annoying my friends and myself, and it's using up my data on my phone which I have to pay for. I've read related discussions, and have tried everything possible. I've restarted my phone. Signed out and back into Apple. It still uses my email and it does not show my number nor does it let me add my number. All it shows is my email as my address, then underneath says "add another email address".

    droopmcc wrote:
    I found the resolution! To recap, My iPad was unable to send/receive iMessages using my iPhone number. It was only showing my email address as an option. It all has to do with your iPhone, not your iPad.
    Go to your iPhone and navigate to Settings>Messages>Send&Receive. At the top, you should notice that it is asking you to sign in using your AppleID. You must sign in on your iPhone or it will not know to sync it up with your iPad. Once you login, you will notice that your phone now shows your phone number and email address. Go back to your iPad and navigate to Settings>Messages>Send&Receive. You need to sign out of your AppleID from here. Simply sign back in and voila! You will get a pop up message telling you what you've done. Go to your iPhone and it will give you similar messages saying that the iPad was set up with that phone number. Enjoy!
    This may have worked for you, but for a growing number of people, it's not working for us.
    -We have no option to select between our phone number or email
    -We have no caller id selection option
    -Recieve & Send only has the email listed (phone # is greyed out and can't be ticked)
    -Signing in and out does nothing
    -Resetting network settings doesn't work
    I'm thinking some of you were just lucky and it started working on it's own again after you did reset the power and what not. For the vast majority and the 290,000 plus views from this topic alone, it isn't working.

  • How do i add a number in a cell which is already formatted

    how do i add a number in a cell which is already formatted

    IT seems that my orginal query has been corrupted
    the orginal question was how to preserve  rows and columns in numbers automatically.ie the cells are not consecutivecell a1 a3 etc
    working on a league table when sorting the league table ,I need to preserve the row and column I can preserve row and column by using the drop down menu on every cell,but would like to do it automatically…

  • To add serial number column

    Dear Experts,
                        I herewith attachedc my  codings i waht to add serial number how to do that i have done something but it is giving all zero values.,.,.,
    *& Report  ZAPPRAISAL_LAG
    REPORT  ZAPPRAISAL.
    *Declaration of type-pools
    TYPE-POOLS SLIS.
    *Declaration of tables
    TABLES : PA0025, PA0001.
    DATA : LV_VALUE TYPE I.
    *Declaration of work area
    DATA: BEGIN OF WA_PA0025,
            PERNR TYPE PA0025-PERNR,
            ENDDA TYPE PA0025-ENDDA,
            BEGDA TYPE PA0025-BEGDA,
            AEDTM TYPE PA0025-AEDTM,
            BWNAM TYPE PA0025-BWNAM,
            DAT25 TYPE PA0025-DAT25,
            GRPNR TYPE PA0025-GRPNR,
            ENAME TYPE EMNAM,
            BUKRS TYPE PA0001-BUKRS,
            number type i,
          END OF WA_PA0025,
           WA_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
           wa_sort  TYPE SLIS_SORTINFO_ALV,
           WA_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.
    DATA: row_number type i.
    *Declaration of internal tables
    DATA : IT_PA0025 LIKE TABLE OF WA_PA0025,
           IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
           I_SORT  TYPE STANDARD TABLE OF SLIS_SORTINFO_ALV,
           IT_EVENTS TYPE SLIS_T_EVENT.
    *selection screen
    SELECTION-SCREEN BEGIN OF BLOCK FF WITH FRAME TITLE TEXT-001.
    *SELECT-OPTIONS S_DATE FOR PA0025-DAT25.
    parameters : p_date type pa0025-dat25.
    parameters : p_date1 type pa0025-dat25.
    SELECT-OPTIONS S_BUKRS FOR PA0001-BUKRS NO INTERVALS.
    SELECTION-SCREEN END OF BLOCK FF.
    *ALV EVENTS
    WA_EVENTS-FORM    = 'HEADER'.
    WA_EVENTS-NAME    = 'TOP_OF_PAGE'.
    APPEND WA_EVENTS TO IT_EVENTS.
    CLEAR : WA_EVENTS.
    *start-of-selection event.
    START-OF-SELECTION.
      SELECT DISTINCT
            A~PERNR
            A~ENDDA
            A~BEGDA
            A~AEDTM
            A~BWNAM
            A~DAT25
            A~GRPNR
            B~ENAME
            B~BUKRS
            INTO TABLE IT_PA0025
            FROM PA0025 AS A
            INNER JOIN PA0001 AS B
            ON BPERNR = APERNR
            WHERE A~DAT25
           between p_date and p_date1
           AND B~BUKRS IN S_BUKRS.
      SORT IT_PA0025 by pernr.
      DESCRIBE TABLE IT_PA0025 LINES LV_VALUE.
    loop at it_pa0025 into wa_pa0025.
    row_number = row_number + 1 .
    WA_PA0025-number   =  row_number.
    *append wa_pa0025 to IT_PA0025.
    endloop.
      perform fcat using '1'  'NUMBER' 'S.no' '12' '' 'C410' 'C'.
      PERFORM FCAT USING '2'  'PERNR' 'Personnel number'    '16'  'X' 'C410' 'C'.
      PERFORM FCAT USING '3'  'ENAME' 'Employee name'       '26'  ''  '' ''.
      PERFORM FCAT USING '4'  'BUKRS' 'Company code'        '15'  ''  '' 'C'.
      PERFORM FCAT USING '5'  'BEGDA' 'Start date'          '11'  ''  '' ''.
      PERFORM FCAT USING '6'  'ENDDA' 'End date'            '10'  ''  '' ''.
      PERFORM FCAT USING '7'  'AEDTM' 'Changed date'        '13'  ''  '' ''.
      PERFORM FCAT USING '8'  'BWNAM' 'Appraiser'           '18'  ''  '' ''.
      PERFORM FCAT USING '9'  'DAT25' 'Appraised date'      '15'  ''  '' ''.
    CLEAR wa_sort.
    wa_sort-fieldname = 'PERNR'.
    wa_sort-up = 'X'.
    APPEND wa_sort TO i_sort.
      CLEAR wa_sort.
      wa_sort-FIELDNAME = 'DAT25'.
      wa_sort-UP = 'X'.
      APPEND wa_sort TO I_SORT.
      CLEAR wa_sort.
      wa_sort-FIELDNAME = 'BUKRS'.
      wa_sort-UP = 'X'.
      APPEND wa_sort TO I_SORT.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM      = SY-CPROG
          I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
          IT_SORT                 = I_SORT
          I_GRID_TITLE            = 'Report'
          IT_FIELDCAT             = IT_FCAT
          IT_EVENTS               = IT_EVENTS
        TABLES
          T_OUTTAB                = IT_PA0025.
    *&      Form  USER_COMMAND
          text
    -->  p1        text
    <--  p2        text
    FORM USER_COMMAND USING U_UCOMM TYPE SY-UCOMM
                            US_SELF_FIELD TYPE SLIS_SELFIELD.
      CASE U_UCOMM.
        WHEN '&IC1'.
          READ TABLE IT_PA0025 INTO WA_PA0025 INDEX US_SELF_FIELD-TABINDEX.
          CASE US_SELF_FIELD-FIELDNAME.
            WHEN 'PERNR'.
              SET PARAMETER ID : 'PER' FIELD WA_PA0025-PERNR.
              CALL TRANSACTION 'PA30'.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    " USER_COMMAND
    FORM FCAT  USING    FP_COL_POS
                        FP_FIELDNAME
                        FP_SELTXT_M
                        FP_OUTPOUTLEN
                        FP_HOTSPOT
                        FP_EMPHASIZE
                        FP_JUST.
      WA_FCAT-COL_POS    =  FP_COL_POS.
      WA_FCAT-FIELDNAME  = FP_FIELDNAME.
      WA_FCAT-SELTEXT_M  = FP_SELTXT_M.
      WA_FCAT-OUTPUTLEN  = FP_OUTPOUTLEN.
      WA_FCAT-HOTSPOT    = FP_HOTSPOT.
      WA_FCAT-EMPHASIZE  = FP_EMPHASIZE.
      WA_FCAT-JUST       = FP_JUST.
      APPEND WA_FCAT TO IT_FCAT.
      CLEAR : WA_FCAT.
    ENDFORM.                    " FCAT
    *&      Form  HEADER
          text
    -->  p1        text
    <--  p2        text
    FORM HEADER .                                               "#EC CALLED
      DATA :     IT_HEADER TYPE SLIS_T_LISTHEADER,
                 WA_HEADER LIKE LINE OF IT_HEADER.
      WA_HEADER-TYP  = 'H'.
      WA_HEADER-INFO = TEXT-006.
      APPEND WA_HEADER TO IT_HEADER.
      CLEAR WA_HEADER.
      WA_HEADER-TYP  = 'S'.
      WA_HEADER-KEY  = TEXT-007.
      CONCATENATE  SY-DATUM+6(2) '.'
                   SY-DATUM+4(2) '.'
                   SY-DATUM(4) INTO WA_HEADER-INFO.   "Current date
      APPEND WA_HEADER TO IT_HEADER.
      CLEAR WA_HEADER.
      WA_HEADER-TYP  = 'S'.
      WA_HEADER-KEY = TEXT-012.
      MOVE LV_VALUE TO WA_HEADER-INFO.
      APPEND WA_HEADER TO IT_HEADER.
      CLEAR WA_HEADER.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY = IT_HEADER.
      CLEAR : IT_HEADER[], WA_HEADER.
    ENDFORM.                    " HEADER
    Thanks and Regards,
    Thirukumaran. R

    hi
    LOOP AT it_pa0025 INTO wa_pa0025.
        row_number = row_number + 1 .
        wa_pa0025-number = row_number.
    " Add this statement here
        MODIFY it_pa0025 INDEX sy-tabix FROM wa_pa0025 TRANSPORTING number.
      ENDLOOP.
    Thanks & Regards

  • How can i add page number?

    how can i add page number in pages...???

    Maybe reading Pages User Guide would be a good idea.
    Yvan KOENIG (VALLAURIS, France) dimanche 26 février 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • Can i combine pdf, word and powerpoint into 1 pdf, and add page number?

    hi, i've been tasked to create a proposal combining these document types into 1 pdf. does anyone know if i can add page number as well, before i pay for subscription?
    thank you!!

    Hi,
    Combine Files tool in PDF Pack can combine multiple files into a single PDF file, but adding page number to each page of the single PDF file has be done in Adobe Acrobat.
    You can subscribe to Acrobat Plus or download Acrobat XI Pro trial version  from www.adobe.com.  Please see more information about Acrobat Plus subscription at https://www.acrobat.com/acrobatplus/en/home.html?trackingid=JPZKR.
    How to add page number in PDF file using Acrobat XI Pro:
    1. Open a PDF file
    2. Select "Tools" from top right corner
    3. Select "Pages" tab
    4. Select "Header & Footer"
    5. Select "Add Header & Footer" from pull down menu
    6. Select location for page number then click "Insert Page Number" button
    7. Click "OK" button
    Hisami

  • How do i add the number from app as same as in my 5s and ipadmini

    my mac bought in2011 iPhone 5 s 2013 ipadmini 2013 alls in the new version.

    Sorry - don't know what it is you are asking. What do you mean by "add the number from app"?
    GB

  • (SOLVED) How to automagically add X number of line to new file in vim?

    Basicly I want to add X number of predefined lines of text to every new file I create in vim; if I create file.cpp I want some text, if I create file.sh I want another text.
    I'm sure this is do-able?
    Last edited by dmz (2009-07-07 17:51:41)

    Brilliant! Thanks.

Maybe you are looking for

  • How to create a clone of database from STANDBY?

    How can i clone a database from physical standby database?

  • Import unicode flat file

    Hello , I try to import a unicode (Windows unicode, not UTF-8) flat file but it couldn't be executed successfully. There is an error message in Deployment Manager. RPE-01013: SQL Loader reported error condition, number -1073741819. My environment con

  • How to get Cost centers a below a cost center from hierarchy using ABAP

    Hi !!          I am currently developing a user application wherin i need to give a dropdown help to the users for cost center field. How ever I need to give him those cost centers in the help which are lower to the cost center to which he is assigne

  • Load data through control file

    Hi , I am the first time loading data , My table definition: <pre> SQL> desc t; Name Null? Type ID NUMBER NAME VARCHAR2(35) And my csv file data: id     name 1     5.0315 2     3.2645 3     1.4975 4     -0.2695 5     -2.0365 And my control file: load

  • Itunes deletes Podcats I want to keep

    Hello, I download video podcasts on to my Ipod. Video-Podcasts I want to keep in Itunes after I have watched them, are being deleted from the Ipod and my computer, after syncing. I have highlighted the settings: Episodes to keep: All episodes, but it