Results 1 to 8 of 8
Thread: Please me figure this out
- 04-30-2012, 12:40 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
Please help me figure this out
when I press the button I expected to see the textfield (TestGroupLayer) but instead I do not see anything at all. It only shows an empty frame. I am trying to learn this GroupLayer since it best suites my needs so please someones help. here is the code :
Java Code:package test.gui; import javax.swing.*; import static javax.swing.GroupLayout.Alignment.*; public class TestGroupLayer extends JPanel { JTextField textField1; public TestGroupLayer() { textField1 = new JTextField (); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addComponent(textField1) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING) ) ))); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) .addComponent(textField1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) ) ))); } }
Java Code:package test.gui; import static javax.swing.GroupLayout.Alignment.BASELINE; import static javax.swing.GroupLayout.Alignment.LEADING; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class TestLayerOne extends JPanel { TestLayerTwo layerTwo; private JButton btn; public TestLayerOne() { initComponents(); } private void initComponents() { btn = new JButton(); btn.setText("Button"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnActionPerformed(evt); } }); add(btn, new GroupLayout(this)); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addComponent(btn) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING) ) ))); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) .addComponent(btn) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) ) ))); } private void btnActionPerformed(ActionEvent evt) { TestGroupLayer groupLayer = new TestGroupLayer (); removeAll (); add (groupLayer, new GroupLayout (this)); validate (); System.out.println("This is a Test"); } }
Java Code:package test.gui; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JTabbedPane; public class TabPanels extends JFrame{ JFrame myFrame = null; // main to run and test this part of the program public static void main(String [] args) { new TabPanels(); } public TabPanels() { JTabbedPane tp = new JTabbedPane(); add(tp); tp.addTab("Tab1",new TestLayerOne()); tp.addTab("Tab2", new TestGroupLayer()); tp.addTab("Tab3", new TestGroupLayer()); setPreferredSize(new Dimension(1360,768)); pack(); setVisible(true); } }
Last edited by atrodeyo; 04-30-2012 at 05:42 AM.
-
Re: Please me figure this out
My suggestion: don't use GroupLayout as it is very difficult to code by hand. Instead use nested JPanels that each use simpler layouts to satisfy your needs.
- 04-30-2012, 03:34 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
Re: Please me figure this out
ok.. but I still would like to know about this problem tho since I think I am so close. So please someone explain it to me .. please please
- 04-30-2012, 05:31 AM #4
Re: Please me figure this out
Do you read the responses to your questions? Evidently not.
http://www.java-forums.org/new-java/...tml#post282826
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-30-2012, 05:43 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
Re: Please me figure this out
well this is a new issue tho. I was able to get rid of my exception problem with yr help and I was able to see the button and the textfield also but when I press the button it disapears also I was trying with GroupLayer.
- 04-30-2012, 06:22 AM #6
Re: Please me figure this out
So once again you didn't click the link I posted.
I sometimes wonder why I bother.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-30-2012, 06:59 AM #7
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
Re: Please me figure this out
if you are talking about the new members guide then yes I did read it but I read it after I posted this and I didnt want to start another thread by changing the title since thats violate one of the rule too.. sorry about that... also I know you mentioned about using different layout but I really want to finish this first so thought someone hopefully and probably will help and point me to the right direction.
-
Re: Please me figure this out
You may not get much help as not many folks I know use GroupLayout to hand code their layouts, so the pool of potential experts to help you in this subject is limited.
Similar Threads
-
can't figure it out myself
By Doyle Raymond in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-18-2011, 03:34 PM -
can someone help me to figure this out >.<
By kissmeeq in forum New To JavaReplies: 2Last Post: 08-01-2011, 03:19 PM -
Can't figure out
By beauti477 in forum New To JavaReplies: 3Last Post: 07-20-2011, 03:58 PM -
Need help - I can't figure it out.
By Joshsmith in forum New To JavaReplies: 2Last Post: 10-23-2009, 10:12 PM -
I can't figure this out
By silvia in forum New To JavaReplies: 3Last Post: 07-20-2007, 04:38 AM
Bookmarks