3

I installed a plugin for eclipse that helps creating a JFrame in a UI. The code generated form the plugin has some strange syntax. I never ever saw something like this in java:

private JPanel b_,cb_,pb_,l_,tf_,ta_contentPane;

public Mainf() {
    b_,cb_,pb_,l_,tf_,ta_contentPane = new JPanel();
    b_,cb_,pb_,l_,tf_,ta_contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    b_,cb_,pb_,l_,tf_,ta_contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(b_,cb_,pb_,l_,tf_,ta_contentPane);
}

how is that even possible? ^^ The standard java compiler sees that as a syntax error. Is there a option to compile this right?

Edit:
I found it again (^^). All of these tools use this syntax.
URL for Eclipse: Help->Install new Software...

WindowBuilder Pro Eclipse Update Site - http://download.eclipse.org/windowbuilder/WB/integration/4.3/

and the Website:

http://www.eclipse.org/windowbuilder/

  • 3
    It looks like the comma is supposed to be part of the variable name as opposed to a list, maybe? So you could potentially search+replace with _ or something. Alternatively, you can install a better plugin. – chessbot Jun 13 '13 at 19:32
  • 1
    are you saying it is compiled in your eclipse with out errors? – pinkpanther Jun 13 '13 at 19:33
  • can't you change variable name? like in matisse? – nachokk Jun 13 '13 at 19:37
  • 1
    Please provide the plugin name. (I'm sure other people will be able to help you better with that information; I just want to know to avoid it. :D) – asteri Jun 13 '13 at 19:55

2 Answers2

0

No, there is no option to compile that right.

private JPanel b_,cb_,pb_,l_,tf_,ta_contentPane;

Is a correct sentence.

b_,cb_,pb_,l_,tf_,ta_contentPane = new JPanel();
b_,cb_,pb_,l_,tf_,ta_contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
b_,cb_,pb_,l_,tf_,ta_contentPane.setLayout(new BorderLayout(0, 0));

Are incorrect sencences.

  • 1
    Yeah, I think OP already figured that part out. Question is: why did the plugin generate that code, and how to fix it. – Edward Falk Jun 13 '13 at 19:51
  • You might also want to explain what the "correct sentence" means. Most likely it is *not* what the OP wants, nor what the plugin meant to generate. – Code-Apprentice Jun 14 '13 at 16:43
0

The code is correct but the variable name generated is a not a valid identifier. The solution is to rename the variable and the code will compile fine.

private JPanel contentPane;

public Mainf() {
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
}
abbas
  • 6,453
  • 2
  • 40
  • 36
  • but then the b_,cb_,pb_,l_ and tf_ JPanels wouldn't exist ^^. The JFrame Builder seems to need those JPanels. – wolfi1571883 Jun 14 '13 at 11:08
  • If the JFrame is expecting 6 JPanels instead of 1 then this is not a valid syntax. You can declare many variables on one line by separating them with comma, but initilizing more than one variable with a comma separation is not a legal syntax. – abbas Jun 14 '13 at 15:26