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 :
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)
)
)));
}
}
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");
}
}
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);
}
}
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.
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
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
db
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.
Re: Please me figure this out
So once again you didn't click the link I posted.
I sometimes wonder why I bother.
db
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.