Community
Participate
Working Groups
When opening visual (Swing) code created in NetBeans, the Visual Editor shows the components in a frame pretty messed up, as if they are not inside the frame. I understand that this is due to differences in the code that the VE creates from the code NetBeans creates (I researched this in the newsgroups). It seems that the code differences are minor, but tedious to apply manually. The VE should either simply make the changes for me, or ask me if I would like it to make them.
Could you be more specific about the code patterns that do not work and/or provide and example class that illustrates the problem? Thanks...
Created attachment 29461 [details] Test JFrame created with NetBeans 4.1 This is a very simple JFrame created in NteBeans 4.1 with a JTextField and a JButton in it. Opening it in Eclipse 3.1.1 with VE 1.1.0.1 will display it as if the JFrame has a size of 0,0. In addition, it looks like the 2 components are not inside the JFrame, and their locations are also incorrect. A few simple code adjustments will make this code look and work correct in Eclipse.
Comment on attachment 29461 [details] Test JFrame created with NetBeans 4.1 Sorry, I mean, of course, it is a simple JFrame subclass.
(In reply to comment #2) > Test JFrame created with NetBeans 4.1 > > This is a very simple JFrame created in NteBeans 4.1 with a JTextField and a > JButton in it. Opening it in Eclipse 3.1.1 with VE 1.1.0.1 will display it as > if the JFrame has a size of 0,0. In addition, it looks like the 2 components > are not inside the JFrame, and their locations are also incorrect. A few simple > code adjustments will make this code look and work correct in Eclipse. Dennis, Thanks for the example.. this helps us understand the code patterns. Currently VE will support using other initialization methods such NetBeans 'initComponents' but the problem here is VE doesn't handle an implicit component such as the content pane which is used in the initComponents method. VE uses an explicit JPanel for it's content pane. In other words, VE can't handle: getContentPane().add(jButton1); As a work around, if you create a new JPanel and set the content pane of the JFrame to this panel, and change all the places in your code that reference 'getContentPane()', VE should work fine. Here's the example with the changed code: private void initComponents() { jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); JPanel jPanel = new JPanel(); // Added this.setContentPane(jPanel); // Added jPanel.setLayout(null); // Changed setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); this.setSize(new Dimension(243, 183)); jTextField1.setText("jTextField1"); jPanel.add(jTextField1); // Changed jTextField1.setBounds(50, 20, 120, 19); jButton1.setText("jButton1"); jPanel.add(jButton1); // Changed jButton1.setBounds(70, 80, 73, 23); pack(); }
Hi Peter, I understand the technical reasons behind the differences in what Eclipse and Netbeans create and I understand the changes in code you need to make to get this to work -- I made them to my project. What I am asking for is that these be made automatically. Maybe I misunderstood you reply. Do you disagree that this should be automated? Thanks, Dennis
(In reply to comment #5) > Hi Peter, > > I understand the technical reasons behind the differences in what Eclipse and > Netbeans create and I understand the changes in code you need to make to get > this to work -- I made them to my project. What I am asking for is that these > be made automatically. > > Maybe I misunderstood you reply. Do you disagree that this should be automated? > > Thanks, > Dennis Dennis, Sorry I wasn't more clear. Yes... I agree with your request that VE make this change automatically. Once VE is able to handle 'implicit' type of components, this type of code pattern with work fine in VE. I left this bug open to be handled as a future enhancement to VE. Regards... Peter