Re: visual editor & gridbagLayout problem.
Mr. X. wrote:
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.
--
RGB