Initialise a array of JTextFields

I need to access an array of JTextfeilds publically because I need to reference it within a different method. But the problem is that I can only initialise it later because it depends on user input.
How can I set it up publically but initialise the size later.
for example
constructor:
public JTextField text[] = null;
public main method()
initialise(int R)
public void initialise(int p)
text[] = new JTextField[p];
}

public class BrokenDesign
  public JTextField[] fields;
  public BrokenDesign()
    fields = new JTextField[0];
  public void onUserInputInitialiseXJTextFields(int x)
    fields = new JTextField[x];
    for (int k = 0; k < x; k++) {
      fields[k] = new JTextField();
}

Similar Messages

  • Array of JPanel and Array of JTextField?

    Hi,
    I try to create array of jpanel and inizialize it in "for" , but when run it give me this error message:
    "Exception in thread "main" java.lang.NullPointerException"
    at the row: "panInsCantante.add(panInsNCC);"
    why?
    (ps. i tried in another code to create array of jtextfield and it give me same error message..)
    here part of code :
          JPanel [] panInsCantante = new JPanel[3];
          for(int i=0;i<=N;i++){
               JPanel panInsNCC= new JPanel();
               panInsNCC.setLayout( new GridLayout(3,1) );
               panInsNCC.add(campoTesto1);
               panInsNCC.add(campoTesto2);
               panInsNCC.add(campoTesto3);
               //panInsCantante[i] = new JPanel();
               //panInsCantante.setLayout( new GridLayout(1,1) );
         panInsCantante[i].add(panInsNCC);

    a question (theoric...)A VERY important question I may add.
    what's the difference between ..
    this instance :
    JPanel [] panInsCantante = new
    JPanel[3];This declares and initializes the array itself, nothing more. No JPanels have been initialized as yet, just the array. It's as if you have now built the shelves to hold the books, but you have no books up there yet...
    and this instance of panInsCantante? :
    panInsCantante[i] = new JPanel();and this initializes each JPanel in the array as you loop through the array. .... and now you have filled the shelves with the books and can use the books.
    You will need them both.
    In all likelihood, the reason for your confusion is that all of your previous arrays were arrays of primative types: int, double, float, and char. In this situation, you don't need to go through the step of initializing the variable.
    But now you are faced for the first time with an array of reference type, an array of Objects. This is a different situation and requires the steps that we have gone through.
    Message was edited by:
    petes1234

  • Array of JTextFields

    If I have an array of JTextFields e.g. tf = new JTextField[i] for 1<i<46, how can I get the cursor to automatically tab to the next field once a string of numbers has been inputted to one of them. I'm trying to design a Scan Frame for barcodes and I want to be able to scan the first one and automatically be able to scan the next and so on
    thanks
    I can show you code if you need it

    You can set actionListener to forcus on the JTextField[0] and make a function to do the action and then use grabforcus to move cursor to the next JTextField. For example
    JTextField exam [] = new JTextField[3];
    the actionperform function is here
    if(e.source == exam[0])
         dosomething;
         exam[1].grabforcus;//you may check the spelling for sure
    and so on for the next array index.
    Hope solving your problem.

  • Add mouselisteners to an array of JTextField objects

    Hi. I am writing a program to emulate a calendar and I though I would do it for each day I would have a JTextField hold the contents of the field. A user could set the event for that time by clicking on the corresponding textfield. I'm still working on saving to file and whatnot, but my question is how can I add motionlisteners to an array of JTextFields?
    Here is what I've written so far:
    for(JTextField c: event)
                   c.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent ev)
                        String in = JOptionPane.showInputDialog("Please Enter event for this time");
                        c.setText(in);
              }I run into I immediate error regarding setting the contents of c within an innerclass. I know it wouldn't be an issue if c was defined as a private variable, but I don't know if that is permitted for the for each loop. Also I get another error I'm not sure of, something about this can only work if the source level is 5.0 which I don't know what that means.
    also outside of this method I've set the object event:
    private JTextField[] event = new JTextField[168];any input would be appreciated.

    When you have an inner class, you can only access variables that are declared final. So, this should work:
    for (int i=0; i <168; i++)
              final JTextField tempEvent = event;
              event[i].addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent ev)
                        String in = JOptionPane.showInputDialog("Please Enter event for this time");
                        tempEvent.setText(in);

  • Custom Document + Array of JTextFields

    Hi,
    I read through the tutorial and managed to get a Custom Document going for my JTextFields (of which i am using quite a few =))
    To cut my code down and aid getting data back from the textfields, I changed them from a page of declarations to a couple of grouped arrays.
    However, now that I have done that, whenever i change the text in one of the textfields, the text in all the textfields in the array change...
    I'm assuming it's something to do with the super.insertString(offs, str, a); that is being called from the Custom Document, but I'm not sure how to fix it up...
    Any help would be most appreciated.
    Cheers
    Andy

    whenever i change the text in one of the textfields, the text in all the textfields in the array change...This means that each text field is using the same document. It's hard to help since you don't post any code. Your code should look something like:
    textField1 = new JTextField()
    textField1.setDocument( new CustomDocument() );
    textField2 = new JTextField()
    textField2.setDocument( new CustomDocument() );

  • Initialise waveform array of 10 elements

    Hi all,
    I would like to create an array of 10 waveform datatype constants to pass into a structure.  Once passed in, 9 of these elements will be extracted and then another added after which the new 10 will be graphed.  Hopefully this will effectively create a continuously updating graph of my data.
    I was wondering if anyone knows how to create a 10 element array using waveform datatypes.
    I look forward to the great help I have received so far.

    Hi,
    The charts are a bit limiting as I would like to see the grid lines so that values can be directly read from the graph.  What I am trying to do is to acquire some data from a liquid nitrogen tank we have and then display it on a graph so that we can see the last four days usage.  This is important for us as if we run out our experiments will fail.
    The only way I can think of doing this is to create a 10 element array and feed it through a shift register into a while loop.  Inside the loop the array will be cut to 9 elements using the subset array function and then the new data point that is acquired will be added to the array.  This would make the new array one point different each time.  Each time the array is appended it would be redrawn effectively showing a continuously acquiring graph.  The obviously the shift register would feed the new array back into the beginning and it would update again.
    I have tried many iterations but there always seems to be a problem.

  • Arrays with JTextField

    JTextField[] textfields = { JTextField inTroop  = new JTextField( 7 ), JTextField inTank  = new JTextField( 7 ) }; im getting an identifier expected error cxan someone point out what i am doing wrong please?

    is there anyway that i could put on a identifier ? sort of like
    JTextField[] textfields = {intank =  new JTextField( 7 ), introop = new JTextField( 7 ) };

  • Initialise the array length via a function

    Dear forum,
    II need a number of integers as an array, but I don't know how many in advance. An I need this array only in the scope, then do waya with it. So I used
    #include <iostream>
    using namespace::std;
    const int f ();
    int main () {
    int array[f ()];
    return 0;
    const int f () {
    return 42;
    . It worked fine under gcc, but CC compains with
    Error: An integer constant expression is required within th\
    e array subscript operator.
    Is there a switch which makes CC swallow this program?
    Cheers, Peter.

    You are posting this question in the C forum, but
    your question is about the C++ compiler.Hello Clamage,
    this I realised 1e-6 s after clicking submit. It shall not happen again. Anyway, thanks for the quick response!
    >
    In standard C++, the dimension of an array allocated
    statically or in a block must be a constant integer
    expression. Reference: C++ Standard, section 8.3.4.
    If g++ allows a non-constant value, that would be
    non-standard extension.... which are getting at you after a while...
    >
    You can get the effect by allocating the array on the
    heap:
    int* array = new int[f()];Indeed. But what made me make the array static is that with new[], you also have to delete[] (which one always forgets).
    >
    But in C++ you have alternatives to C-style arrays.
    You can use the standard vector class template. It
    manages memory for you, allows a vector to be
    expanded, optionally checks subscripts for being in
    range. When you create a vector, you can specify the
    starting capacity when you know the sizeI should try this.
    Once again, thanks for your patience!
    Cheers, Peter.

  • Listening to MouseEvents in an array of JTextFields

    // BlockWerteFeld is a JTextFiled
    private BlockWerteFeld wertedArray[]= {
            null,null,null,null,null,null,
            null,null,null,null,null,null,
            null,null,null,null,null,null,
            null,null,null,null,null,null
    for ( int i = 0 ; i <= GESAMT_SUMME ; i++ ){
                werteArray = new BlockWerteFeld(
    "tfWert" + i,
    i * Jobs.BLOCK_HOEHE,
    Jobs.BLOCK_LINKS+ Jobs.BLOCK_BREIT
    // some more settings
    werteArray [i].addMouseListener(eventHandler);
    panelBlock.add( werteArray[i]);
    private EventHandler eventHandler = new EventHandler();
    // inner Class
    class EventHandler implements
    java.awt.event.ActionListener,
    java.awt.event.KeyListener,
    java.awt.event.MouseListener{
    public void mouseEntered(MouseEvent e) {
    for ( int i = 0; i < werteArray.length; i++ ){
    if ( e.getComponent() =??
    // more Events handled
    How can I know, that "werteArray " has been mouseEntered, and which element ?
    TIA Hanns

    Hi,
    You have already added the listener (you did that in the first loop).
    Your second loop should have this
    for ( int i = 0; i < werteArray.length; i++ ){
       if ( e.getComponent()  = werteArray) {
    //werteArray[i] is the source
    Kaj

  • Jtextfield and array

    Hi ALL
    I'm trying to create a Jtextfield but i also want to have an array on the Textfield, is their a simple way of doing this. I have tried but failed so can anyone help please.
    wen i try i get nopointerexception (frustrating)

    yea i tried
    int i;
    for(i=0; i < array.length; i++)
    JTextField[] array = new JTextField;
    don't compile                                                                                                                                                                                                                                               

  • JTextField array help

    Hey guys,
    I'm working on a java GUI right now and I've come up with a problem, hopefully you guys can help.
    I have a page that contains 50 text fields in 2 columns, so instead of making 50 lines of text field code, I decided to make an array of text fields and a for loop to cycle through each one (setting sizes, colors, editable, etc). Now the problem I'm running into is I will later down the road like to setText in these but it will be very cumbersome to have to call them by the arrayName[index #]. Just so I can better express what I mean heres is how I have to call each text field right now:
    arrayName[0].setText("1");
    arrayName[1].setText("2");
    This is how I'd like to be able to call each field:
    1stTextField.setText("1");
    2ndTextField.setText("2");
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name? If not, is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1];
    Thanks for the help guys.

    50 text fields in 2 columns... why not just use a JTable?
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name?Try a HashMap
    is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1]; Yes, exactly as you coded it up

  • JTextField array

    I�m using an array of jTextFields within a pane and I want to know which of this jTextFields was edited. I used the getSource method but I cannot interpret the data since I don�t get the index of the jTextField.

    Or, if you really do want to know which field was editted, here's one possible solution
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.*;
    public class JTextFieldTester extends JFrame implements ActionListener{
        JTextField[] fields;
        public JTextFieldTester() {
            JPanel mainPane = (JPanel) getContentPane();
            mainPane.setLayout(new GridLayout(5,0,5,5));
            fields = new JTextField[5];
            for (int i = 0 ; i < 5 ; i++){
                fields[i] = new JTextField(20);
                fields.setName(""+i);
    fields[i].addActionListener(this);
    mainPane.add(fields[i]);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
    public void actionPerformed(ActionEvent e) {
    Component comp = (Component) e.getSource();
    if ( comp instanceof JTextField) {
    System.out.println(comp.getName());
    public static void main(String[] args) {
    new JTextFieldTester();
    This depends on user hitting enter after editting but you can do simular things with other types of events. The major point is that by assigning a name to each field you can rapidly determine which field fired the event. This is probably far more efficient for very large arrays of tields.
    Good Luck
    DB

  • Transient array initialisation

    Hi all
    Having a problem initialising transient arrays in my applet, hope somebody can help. I've been trying to declare the array as follows:
    public static boolean[] authenticationDone = JCSystem.makeTransientBooleanArray((short)1,JCSystem.CLEAR_ON_RESET);
    And I get this error from the converter(Gemplus RADiii)
    "unsupported bytecode invokestatic in clinit method"
    I've looked into this and found that invokestatic is supported in the JCVM spec. However I have found that there is only limited support for initialisation of static field values.
    Can anyone notice what I'm doing wrong in my initialisation, how else should a transient array be initialised? TIA
    Tony

    Not true. All data whether RAM or E2P should be allocated in the constructor or prior to the applets register().
    Look at the Sun samples and you'll notice all transient array allocations are performed in the constructors. ( Java Purse constructor for example ).
    If you attempt to allocate the memory outside the constructor/register(), you could run the risk of not having available memory.
    What do you mean that about it should be init at runtime ? The JCRE is always running on a card when powered on.

  • How to get an array variable to update in a loop

    Hi
    I have an array of doubles called cps that contains a double h.
    the array is defined out of the loop.
    The loop defines the value of h and uses that array to do something. How can I get the array to update h at every iteration of the loop?
    // STAR-CCM+ macro: test.java
    package macro;
    import java.util.*;
    import star.common.*;
    import star.base.neo.*;
    import star.vis.*;
    import star.base.report.*;
    public class test extends StarMacro {
    public void execute() {
    double h ;
    int i;
    double[] cps= new double[] {75.9042408986955, 52.51153872409542, h, 76.51180919240942, 49.49901260109725, h, 77.70163043426585, 49.67622002009714, h, 78.35982941912259, 46.537117169241895, h, 78.08136061783705, 45.42324196409971, h, 75.67640278855279, 44.840989015957206, h, 68.73999810198555, 40.942425797959565, h, 66.66413976512966, 44.511889523528836, h, 67.85396100698608, 44.99288108938568, h, 68.81594413869979, 45.65108007424243, h, 69.37288174127089, 46.081440948956455, h, 68.99315155769969, 46.992793389527336, h, 68.38558326398577, 48.005407212383865, h, 67.8792763525575, 48.81549827066909, h, 73.423337032697, 51.954601121524334, h};//coordinates of constrained section plane
    Simulation simulation_0 =
    getActiveSimulation();
    // CREATING CONSTRAINED PLANE SECTIONS //
    Region region_0 =
    simulation_0.getRegionManager().getRegion("main domain;main domain;NONE");
    Units units_0 =
    ((Units) simulation_0.getUnitsManager().getObject("m"));
    i = 0;
    for ( h = 0.5; h <= 2; h = h + 0.5) {
    i = i + 1;
    ConstrainedPlaneSection constrainedPlaneSection_i =
    (ConstrainedPlaneSection) simulation_0.getPartManager().createConstrainedPlaneImplicitPart(new NeoObjectVector(new Object[] {region_0}), new DoubleVector( cps ), units_0); // Sets Plane Boundaries (as mapped) //
    LabCoordinateSystem labCoordinateSystem_0 =
    ((LabCoordinateSystem) simulation_0.getCoordinateSystemManager().getObject("Laboratory")); // Defines Lab Coordinate System (Does this once). //
    constrainedPlaneSection_i.setCoordinateSystem(labCoordinateSystem_0); // Sets this planes coordinate system //
    Coordinate coordinate_i =
    constrainedPlaneSection_i.getOriginCoordinate();
    coordinate_i.setCoordinate(units_0, units_0, units_0, new DoubleVector(new double[] {71.92329015, 46.4835809, 0.5})); // Sets the origin for the plane //
    constrainedPlaneSection_i.setPresentationName("Unit 1 " + h + "m");
    }

    double h ;
    double[] cps= new double[] {75.9, 52.5, h, 76.5, 49.4, h,  // simplifiedLooking at your code I see that you have initialised your array with the value of the variable h scattered throughout it. Are you asking how you can update these "h" values in the array each time around the loop? eg:
    Initial array: 75.9, 52.5, 0.0, 76.5, 49.4, 0.0
    1st iteration: 75.9, 52.5, 999.999, 76.5, 49.4, 0.0
    2nd iteration: 75.9, 52.5, 999.999, 76.5, 49.4, 999.999
    Something like that.
    If so then you need to know what the indicies of the numbers you want to update which may not be a simple matter. Perhaps an array is not what you want here but maybe a Map instead.

  • Added a 2nd Array on my Xserve RAID, Though it's not appearing in disk utilityt

    I have an Xserve RAID unit. Up until now I have just been running 1 side of it with 7 drives on RAID 5 = about 4TB. I recently picked up another identical RAID unit with 7 drives to fill out the right hand bay of the unit doubling our capacity. I have installed these and initialised the array which took about 48 hours, it's now showing as online and green lights all the way.
    Now I've gone to make use of the extra space but it is not showing as available in the mounted RAID icon on the desktop, nor will the new array appear in disk utility. When I access server admin however, on the overview screen it shows I have 8TB on offer. Contrary to this in the system profiler the 'Fibre Channel Domain 2' is not reporting any SCSI devices unlike 'Fibre Channel Domain 0' - Not sure this is related.
    If anyone can help me gain access to the new found 4TB I would be greatly appreciative.

    it is not showing as available in the mounted RAID icon on the desktop
    It won't.
    The XServe RAID is really built as two independent RAID controllers and drive sets in one enclosure.
    The 7 left-most drives are connected to the top controller, and the 7 right-most drives are connected to the bottom controller. They are independent. There's no way to build a single 14-drive array - the best you can do is build two 7-drive arrays.
    What you should find is that if you connect the bottom controller to your server, the second array should appear on the desktop, separate and distinct from your existing volume.
    If you really need to expand your volume to cover all 14 drives then you'll need to use software RAID 0 (striping) on the server to meld both of the 7-drive arrays into a single logical volume.

Maybe you are looking for

  • Is Mac book pro useful for Video Editing and VFX Work?

    Hi Apple Team and Final Cut Pro Team,     I am Video Editor and Motion Graphic Artist. I do a lot of Video Editing work and I have to spend hours sitting in front of my Desktop and this is getting so hectic for me. So I'm thinking of buying a Mac boo

  • IS IT POSSIBLE TO INSERT A PICTURE ON THE LEOPARD WALLPAPER

    I like the standard wallpaper that appeared after i installed leopard. I would love to have some personal photos, even just one, appear in a small box, maybe 2.5x3 inch, or other size. I just dont like when the entire desktop is occupied by personal

  • Safari browser and refreshing issue.

    Lets say I am on a forum page, I can refresh the page in two ways. Either I hit the refresh button on top or hit the bookmark page of the same page. This works on my old phone and the replacement, except for facebook issue. On facebook, it did it thi

  • Why can't I download the latest update to my Macbook?

    I have 10.6.8 on my white Macbook from 2008. But I wan't the latest update, 10.7.2 or later, but I can't fin any update? Why?

  • Repository Viewing inhibited (local workspace error)

    When opening LifeCycle Workbench I encounter the following Exception: "An error was encountered while trying to reference the local workspace. Repository Viewing inhibited." Another error that may (or may not) be related occurs when I attempt to drag