Results 1 to 3 of 3
Thread: Adding to GridBagLayout
- 10-11-2010, 12:05 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
Adding to GridBagLayout
Hello community,
got a problem with adding my Components via GridBagLayout.
If I create a new JButton while adding it to the container everything works fine. If I initialize a global JButton field before, then try to add it to the container, it will not work. Im very confused because i cannot see a difference between this methods.
DOES NOT WORK
WORKSJava Code:JLabel lblHeadline; (...) lblHeadline= new JLabel(title); add(lblHeadline, c);
Here is where the problem exactly appears in my classes.Java Code:add(new JLabel(title), c);
Java Code:public class SpieltagGUI extends JFrame { private Client cl; private Spielplan plan; private Tabellenplatz[] platzierungen; private String teamName; public [B]JLabel lblHeadline[/B], lblStatus, lblPaarung, lblWürfel; (...) public SpieltagGUI(Spielplan plan, Tabellenplatz[] platzierungen, String teamName, Client cl) { super(); String title="Spieltag "+plan.n+" : "+teamName; setTitle(title); this.cl=cl; this.plan=plan; this.platzierungen=platzierungen; this.teamName=teamName; setLayout(new GridBagLayout()); MyGridBagConstraints c= new MyGridBagConstraints(); // LABELS [B]lblHeadline= new JLabel(title);[/B] c.setValues(0, 0, 3, 1, 1.00, 1.00, 3); [B]add(lblHeadline, c);[/B] (...)Sorry for maybe not the best english.Java Code:public class MyGridBagConstraints extends GridBagConstraints { public void setValues( int x, int y, int width, int height, double weightx, double weighty, int vfill ) { switch (vfill) { case 0: this.fill = GridBagConstraints.NONE; break; case 1: this.fill = GridBagConstraints.HORIZONTAL; break; case 2: this.fill = GridBagConstraints.VERTICAL; break; default: this.fill= GridBagConstraints.BOTH; break; } this.gridx = x; this.gridy = y; this.gridwidth = width; this.gridheight = height; this.weightx = weightx; this.weighty = weighty; } }
Thanks for any advices!
splen
- 10-11-2010, 06:53 PM #2
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates your problem. not all your code, but not uncompilable snippets either.
db
- 10-12-2010, 02:57 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
When i try the same thing in a small GUI-Testclass, it works fine.
Thought maybe in the code posted, there is a strange mistake anywhere.
My whole project is too huge for posting. Even this small piece of code was shortened to be
logical to you. If you dont see why it shouldn't work in here, its okay.
Thanks for your info anyways!
Similar Threads
-
Adding and removing components from a GridBagLayout
By peterhabe in forum New To JavaReplies: 4Last Post: 09-19-2010, 10:13 PM -
[AWT] GridBagLayout Help.
By Sandia_man in forum AWT / SwingReplies: 2Last Post: 05-23-2010, 08:54 PM -
help with gridbaglayout
By robertbob in forum AWT / SwingReplies: 5Last Post: 05-18-2010, 04:14 AM -
GridBagLayout
By MuslimCoder in forum New To JavaReplies: 1Last Post: 01-15-2009, 08:54 PM -
gridbaglayout
By newtojava7 in forum New To JavaReplies: 4Last Post: 01-27-2008, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks