visual editor & gridbagLayout problem.

M

Mr. X.

Hello.
I am using visual editor with eclipse.
Eclipse version 3.3.3.1
VE version 1.3
JRE 1.6.

For some reason, I don't know,
the program refuse to handle with gridBagLayout.

i.e :
setLayout(new GridBagLayout()) - return to an error :

(There is "!" sign at to left corner of the main design container object,
and when mouse on it I see :

.... ClassNotFoundException(GridBagLayout)



SetLayout(new GridLayout() is fine.



When insted of new GridLayout(), I did :

GridBagLayout gbl;

gbl = new GridBagLayout();

....

setLayout(gbl);



I got the message :

IllegalArgumentException Expression "gbl" is too complicated



Why so ?



Thanks :)
 
A

Andrew Thompson

Hello.
I am using visual editor with eclipse.

You are in way over your head.

I suggest you get rid of the IDE you do not
know how to use and instead learn how to code
Java. After having done so, you might find you
can get the 'automagic' IDE to do what you want.
For some reason, I don't know,
the program refuse to handle with gridBagLayout.

Using the few code snippets you reported, I
came up with this simple code..

<sscce>
import java.awt.*;

class TestGBL {

public static void main(String[] args) {
GridBagLayout gbl;
gbl = new GridBagLayout();
Frame f = new Frame();
f.setLayout( gbl );
}
}
</sscce>

That compiles and runs cleanly here, with no
errors.

In future, I strongly recommend you submit
complete code examples, and copy/paste error
messages, since I had never heard error messages
quite like you quoted.

Also, a good group for Java beginners is
comp.lang.java.help.
 
M

Mr. X.

The error I have described is not related to some kind programming error,
but it is related to some kind of Visual Editor problems.

What may be wrong on using Visual Editor & GridBagLayout ?

Thanks :)
 
R

RedGrittyBrick

Mr. X. said:
The error I have described is not related to some kind programming error,
but it is related to some kind of Visual Editor problems.

I think you'll find you are mistaken. 99.99% of the strange and
mysterious problems I have encountered are due to programming error.
Either foolish mistakes or not understanding some aspect of the language
or libraries (or their limitations).
What may be wrong on using Visual Editor & GridBagLayout ?

Almost anything. I would find it pointless to ask people to make
thousands of random guesses hoping that one of them will somehow look
like a right answer to me.

Roedy is right: I also recommend you cease using visual editor (or cease
using GridBagLayout).

Try posting short complete compilable examples - you'll get answers much
quicker.
 
M

Mr. X.

I think it is related to things I should do and not to do with Visual
Editor.
(Are there any rules ?)

I need gridBagConstraint to be private, so I can use it anywhere on code,
but it is declared on the initialize routine, by defualt, so what else can I
do ?

My code :
--------------
import java.awt.ComponentOrientation;

import java.awt.GridBagLayout;

import javax.swing.JPanel;

import java.awt.GridBagConstraints;

import java.awt.Insets;

import javax.swing.JLabel;


public class myObject extends JPanel {


private static final long serialVersionUID = 1L;


private JLabel jLabel = null; // @jve:decl-index=0:visual-constraint="35,11"

private GridBagConstraints gridBagConstraints; // this I have declared
manually.




* This is the default constructor

*/

public MyObject() {

super();

initialize();

}


/**

* This method initializes this

*

* @return void

*/

private void initialize() {

GridBagLayout gbl;

gbl = new GridBagLayout();


jLabel = new JLabel();

jLabel.setText("JLabel");

gridBagConstraints = new GridBagConstraints();

setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

gridBagConstraints.gridx = 0;

gridBagConstraints.gridy = 0;

gridBagConstraints.weightx = 1;

gridBagConstraints.weighty = 1;

gridBagConstraints.ipadx = 150;

gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;

gridBagConstraints.insets = new Insets(1, 1, 1, 1);

gridBagConstraints.anchor = GridBagConstraints.WEST;

setSize(300, 200);

setLayout(gbl);

add(jLabel, gridBagConstraints);

}


} // @jve:decl-index=0:visual-constraint="29,4"
 
A

Andrew Thompson

My code :

Sigh.. after fixing the line wrap*, and changing
the class name from myObject to MyObject to match
both common nomenclature* and supposed meaning, I
discovered this was not an SSCCE because it did not
contain a main()*. Another thing that made the code
confusing was the entire lack of indentation*.

When I linked to the SSCCE document, the real
intent was that you might read it and gain
something from it.

Please read it.

* All the things mentioned above, are discussed
in the SSCCE document.
 
R

RedGrittyBrick

Mr. X. said:
I think it is related to things I should do and not to do with Visual
Editor.
(Are there any rules ?)

I don't use VE. I suggest you avoid it as it seems to be causing you
confusion.
I need gridBagConstraint to be private, so I can use it anywhere on code,
but it is declared on the initialize routine, by defualt, so what else can I
do ?

Why do you need to use your gridBagConstraint variable anywhere other
than in initialize()?
My code :

[code snipped - see below]

Your code does *not* produce the errors you referred to earlier:

I *don't* get 'ClassNotFoundException(GridBagLayout).'

I *don't* get 'IllegalArgumentException Expression "gbl" is too
complicated.'

The code below runs fine, whether it does what you want is impossible to
guess.

------------------------------- 8< ----------------------------
import java.awt.ComponentOrientation;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class MrXsGridBagLayoutProblem extends JPanel {

private static final long serialVersionUID = 1L;

private JLabel jLabel = null;

private GridBagConstraints gridBagConstraints;

public MrXsGridBagLayoutProblem() {
super();
initialize();
}

private void initialize() {
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
setSize(300, 200);

GridBagLayout gbl;
gbl = new GridBagLayout();
setLayout(gbl);

gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1;
gridBagConstraints.weighty = 1;
gridBagConstraints.ipadx = 150;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new Insets(1, 1, 1, 1);
gridBagConstraints.anchor = GridBagConstraints.WEST;

jLabel = new JLabel("Jlabel");
add(jLabel, gridBagConstraints);
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JPanel p = new MrXsGridBagLayoutProblem();
JFrame f = new JFrame("Mr X has a problem");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}

}
------------------------------- 8< ----------------------------

I did reorder your code a little so I could see more clearly what you
were doing. However it is essentially the same code. I had to add a
main() as Andrew noted. You are not making it easy for others to help you.

Please read <http://sscce.org/>, as others have suggested, and explain
your problem more carefully.
 
A

Andrew Thompson

On May 23, 8:05 pm, RedGrittyBrick <[email protected]>
wrote:
...
Please read <http://sscce.org/>, as others have suggested, and explain
your problem more carefully.

Thanks. Until you posted that (and I checked back),
I actually thought I'd linked to it earlier.

To the OP. *My deep apologies.* My second post was
written in some irritation, because you had failed
to read the document that /I had failed to link to
earlier, and I failed to specifically mention./ :-(

Luckily, RGB was watching the thread as well.
 
A

Andrew Thompson

My code :

Sigh.. after fixing the passage wrap*, and changing
the flaw name from myObject to MyObject to match
both safer nomenclature* and established character, I
adopted this was not a SSCCE because it did not
avoid a postal()*. Another tattoo that made the incidence
refreshing was the dependent lack of indentation*.

When I linked to the SSCCE document, the easier
intent was that you might read it and gain
something from it.

Please read it.

* All the wetwares burdened above, are reflected
in the SSCCE document.

--
Mark T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The most important thing is for us to find Osama bin Laden.
It is our number one priority and we will not rest
until we find him."

--- Adolph Bush,
9/13/01
 
A

Andrew Thompson

On May 23, 8:05=A0pm, RedGrittyBrick <[email protected]>
wrote:
=2E..
Please read <http://sscce.org/>, as others have suggested, and explain
your problem more carefully.

Thanks. Until you posted that (and I checked back),
I FINALLY thought I'd linked to it earlier.

To the OP. *My enthusiastic apologies.* My forever post was
ambiguous in some irritation, because you had substantiated
to read the document that /I had cauterized to link to
earlier, and I enforced to absolutely hate./ :-(

Luckily, RGB was watching the capability as well.

--
Woody T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"I mean, there needs to be a wholesale effort against racial
profiling, which is illiterate children."

--- Adolph Bush,
Second presidential debate, Oct. 11, 2000
(Thanks to Leonard Williams.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top