0

I am using Eclipse Window Builder, and in my program, I would like to ask the user to enter the highest degree of the polynomial and based on his answer, I would like my program to display n text boxes and n label for him to enter the coefficient of each x

Example: Enter Highest Degree: 3

-- X^3

-- X^2

-- X^1

-- X^0

Anyone knows how this can be done?

  • "Anyone knows how this can be done?" - Yep, with some research and good old-fashioned effort. – rmlan Dec 06 '16 at 13:31
  • 1
    You may want to look into adding them programmatically rather than with the Window Builder. – Baz Dec 06 '16 at 13:35
  • @Baz you mean a large text box and then create a parser to separate the inputs? I thought of that, but for large degrees, user wont be able to easily edit the input... User is expected to work in GF(2^168) so polynomials with highest degree of 168 (I already made a reduce function in the code, I just need to find a way to read the polynomial from the user) – Fares Ismail Dec 06 '16 at 13:44
  • 1
    No, I mean create as many `Text` widgets as you need, but not using the Window Builder. – Baz Dec 06 '16 at 13:52
  • @Baz do you know how I could do that? (the code to generate x text boxes next to x lables where lable is in function on x)? – Fares Ismail Dec 06 '16 at 14:09

1 Answers1

2

If you know the number of boxes you need, simply pass that number and a parent Composite (with the Layout you need) to the method below:

private void addBoxes(Composite parent, int number)
{
    for(int i = 0; i < number; i++)
    {
        Text text = new Text(parent, SWT.BORDER);
        // Maybe add them to a List here so you can use them again later.
    }
}

If you want to call this method more than once, remember to dispose() of the old Texts before you do so.

Baz
  • 36,440
  • 11
  • 68
  • 94