Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18900 > unrolled thread

GridBagLayout in CardLayout....Problems

Started bydomenik.brugger@googlemail.com
First post2012-09-23 16:49 -0700
Last post2012-09-23 18:26 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  GridBagLayout in CardLayout....Problems domenik.brugger@googlemail.com - 2012-09-23 16:49 -0700
    Re: GridBagLayout in CardLayout....Problems markspace <-@.> - 2012-09-23 18:26 -0700

#18900 — GridBagLayout in CardLayout....Problems

Fromdomenik.brugger@googlemail.com
Date2012-09-23 16:49 -0700
SubjectGridBagLayout in CardLayout....Problems
Message-ID<b5dfe2a8-8426-4320-a6fb-6a3354446066@googlegroups.com>
Hello,
i have a probleme with the cardLayout.

i have a jpanel with cardlayout and two cards in it with GridBagLayout.
In each card is a JButton. At a click there should be shown the next card with the other button.
But the buttons will be shown together when i start the program.

My Code:
[code]
package EP.GUI;
import static EP.UTIL.Sprache_DE.stRegeln;
import static java.awt.GridBagConstraints.BOTH;
import static java.awt.GridBagConstraints.LINE_START;
import static java.awt.GridBagConstraints.REMAINDER;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class CardLayoutExample1 extends MyGridBagContraints{
  
	private CardLayout cardLayout;
	public JButton    button1, button2;
	private JPanel     panel1, panel2, jPanelEigen, jPanelGridBag;
    
	
  
  public CardLayoutExample1(){   
	  super();
	  
	  this.setSize(500,500);
		this.setLayout(new GridBagLayout());
		this.setVisible(true);
		this.setLocation(50,50);
		this.setTitle(stRegeln);
		this.addWindowListener(new WindowListener() {
			public void windowOpened(WindowEvent arg0) {}
			public void windowIconified(WindowEvent arg0) {}
			public void windowDeiconified(WindowEvent arg0) {}
			public void windowDeactivated(WindowEvent arg0) {}
			public void windowClosing(WindowEvent arg0) {
				
			}
			public void windowClosed(WindowEvent arg0) {}
			public void windowActivated(WindowEvent arg0) {}
		});
		
    cardLayout = new CardLayout();
    jPanelEigen = new JPanel(cardLayout);
    
    panel1 = new JPanel(new GridBagLayout());  
    panel2 = new JPanel(new GridBagLayout());
  
    button1 = new JButton("Button1");
    button2 = new JButton("Button2");
    
    jPanelEigen.add(getPanel1(), "card1");
    jPanelEigen.add(getPanel2(), "card2");
    
    cardLayout.show(jPanelEigen, "card1");
    this.add(jPanelEigen);
    pack();
    createListener();
    setVisible(true);
  }

  private JPanel getPanel1(){
	  
	  panel1.setBackground(Color.gray);
	  setDefaultGB();
		addGB(button1, gridx, gridy, 
				gridwidth = REMAINDER, gridheight, fill, 
				weightx, weighty, anchor, 
				insets);
	    
	    return panel1;
  }
  private JPanel getPanel2(){
	  
	  panel2.setBackground(Color.yellow);
	  setDefaultGB();
		addGB(button2, gridx, gridy, 
				gridwidth = REMAINDER, gridheight, fill, 
				weightx, weighty, anchor, 
				insets);
	  
	  return panel2;
  }
  
  
  private void createListener(){
    ActionListener al = new ActionListener(){
      public void actionPerformed(ActionEvent e){
        cardLayout.next(jPanelEigen);   
      }      
    };
    button1.addActionListener(al);
    button2.addActionListener(al);
    
    addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){ 
        System.exit(0); 
      }
    });
  }
}

[/code]

I have no idea what to do and hope you can help me.
Thanks.

[toc] | [next] | [standalone]


#18902

Frommarkspace <-@.>
Date2012-09-23 18:26 -0700
Message-ID<k3ocra$4hd$1@dont-email.me>
In reply to#18900
On 9/23/2012 4:49 PM, domenik.brugger@googlemail.com wrote:

> I have no idea what to do and hope you can help me.

I have no idea what to do either:

>
> My Code:
> [code]
> package EP.GUI;
> import static EP.UTIL.Sprache_DE.stRegeln;
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> public class CardLayoutExample1 extends MyGridBagContraints{
                                           ^^^^^^^^^^^^^^^^^^^


This doesn't help us.  Do you really think we can guess what is 
happening when there are several methods in your code that you didn't 
show us?  Please post something compiles, i.e., an SSCCE:

http://sscce.org/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web