Trouble modelling inner classes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble modelling inner classes

Maria Florencia Metelico
The visual editor seems to dislike inner classes.

T
he VE says “java.lang.IllegalAccessException(Class cuentas.ABM$CampoCod is non-static inner class. These cannot be instantiated at this time.) ” and refuses to show a preview.

The code runs without problems.

I'm using Eclipse SDK 3.5.2 and Visual Editor 1.4.0.

Thanks,

Maria Florencia

------------------------------------------------------------

package cuentas;

import java.awt.Rectangle;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class ABM  extends JDialog {
        private JPanel jContentPane = null;
        private CampoCod jtxCodCuenta = null;
        private CampoRs jtxRazonSoc;
       
        private class CampoRs extends Campo_2 {
            public CampoRs() {super();}
            public void doSetDatos() {
            System.out.println("Dentro Razon Soc " + getText());
            }
        }

        private class CampoCod extends Campo_2 {
            public CampoCod() {super();}
            public void doSetDatos() {
            System.out.println("Dentro Cod Cuenta " + getText());
            }
        }
       
       
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new ABM();}
            });
        }

        public ABM() {
            super();
            setLocation(0,50);
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            initialize();
        };

        private void initialize() {
            setSize(567, 154);
            setContentPane(getJContentPane());
            setResizable(false);
            setVisible(true);
        }
       
        private JPanel getJContentPane() {
            jContentPane = new JPanel();
            jContentPane.setLayout(null);

            JLabel jlbCuenta = new JLabel("Cuenta");
            jlbCuenta.setBounds(new Rectangle(4,12,80,20));
            jContentPane.add(jlbCuenta, null);

            jtxCodCuenta = new CampoCod();
            jtxCodCuenta.setBounds(new Rectangle(87, 12, 80, 20));
            jContentPane.add(jtxCodCuenta, null);

            jtxRazonSoc = new CampoRs();
            jtxRazonSoc.setBounds(new Rectangle(170, 12, 373, 20));
            jContentPane.add(jtxRazonSoc);

            return jContentPane;
        }



package cuentas;

import java.awt.AWTKeyStroke;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;

import javax.swing.DefaultFocusManager;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

public class Campo_2  extends JTextField {

            private static final long serialVersionUID = 1L;
            public static int alto = 20;

            public static void main(String[] args) {}

            public Campo_2() {
            super();
            TeclaEnter();
            generarEventos();
            setFocusTraversalKeysEnabled(true);

            };

            public Campo_2(int x, int y, int width) {
            super();   
            TeclaEnter();
            generarEventos();
            int height = alto;
            setBounds(new Rectangle(x, y, width, height));
            setFocusTraversalKeysEnabled(true);
            };  

            public void Reposicionar(int x, int y, int width) {
            int height = alto;
            setBounds(new Rectangle(x, y, width, height));
            }

            public void doSetDatos() {}
            private boolean Validacion() {return true;}


            private void TeclaEnter() {
            Set<AWTKeyStroke> forwardKeys = getFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
            Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys);
            newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
            setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
            };

            private void generarEventos() {
            setInputVerifier(new InputVerifier() {
                public boolean verify(JComponent input) {
                            boolean bOK = Validacion();
                            if (bOK) {
                            doSetDatos();
                            }
                return bOK;              

                } } );
            addFocusListener(new java.awt.event.FocusListener() {
                public void focusLost(java.awt.event.FocusEvent e) {
                }
                public void focusGained(java.awt.event.FocusEvent e) {
                Component component = e.getComponent();
                DefaultFocusManager focusManager = new DefaultFocusManager();
                if (!(component.isEnabled())) {
                    focusManager.focusNextComponent(component);
                };
                }
            });

            }
        }









_______________________________________________
ve-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/ve-dev
Reply | Threaded
Open this post in threaded view
|

Re: Trouble modelling inner classes

Eric Clayberg
Having your custom components be valid, public JavaBeans is pretty
much a requirement for any Java GUI builder. I am not aware of any
that will work with custom components defined as private, inner
classes. Convert your private, inner classes into public, standalone
classes, and I bet it will work fine.

-Eric

>The visual editor seems to dislike inner classes.
>
>The VE says "java.lang.IllegalAccessException(Class
>cuentas.ABM$CampoCod is non-static inner class. These cannot be
>instantiated at this time.) " and refuses to show a preview.

_______________________________________________
ve-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/ve-dev
Reply | Threaded
Open this post in threaded view
|

Re: Trouble modelling inner classes

Maria Florencia Metelico
In reply to this post by Maria Florencia Metelico
Thanks Eric, but the problem in the inner class I want to access to
variables defined in the outer class.


---------------

Having your custom components be valid, public JavaBeans is pretty much
a requirement for any Java GUI builder. I am not aware of any that will
work with custom components defined as private, inner classes. Convert
your private, inner classes into public, standalone classes, and I bet
it will work fine.

-Eric


The visual editor seems to dislike inner classes.


The VE says "java.lang.IllegalAccessException(Class
cuentas.ABM$CampoCod is non-static inner class. These cannot be
instantiated at this time.) " and refuses to show a preview.





_______________________________________________
ve-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/ve-dev
Reply | Threaded
Open this post in threaded view
|

Re: Trouble modelling inner classes

Eric Clayberg

>the problem in the inner class I want to access to variables defined
>in the outer class.

There are a lot of ways you can do that without using an inner class.

-Eric

_______________________________________________
ve-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/ve-dev