java.awt.CardLayout.show()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(461)

本文整理了Java中java.awt.CardLayout.show()方法的一些代码示例,展示了CardLayout.show()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CardLayout.show()方法的具体详情如下:
包路径:java.awt.CardLayout
类名称:CardLayout
方法名:show

CardLayout.show介绍

[英]Flips to the component that was added to this layout with the specified name, using addLayoutComponent. If no such component exists, then nothing happens.
[中]使用addLayoutComponent翻转到使用指定name添加到此布局的组件。如果不存在这样的组件,那么什么也不会发生。

代码示例

代码示例来源:origin: stackoverflow.com

private CardLayout cardlayout = new CardLayout();
private JPanel cards = new JPanel(cardlayout);
 cards.add(createUserAgreePanel(), USER_AGREEMENT);
 cards.add(createUserInfoPanel(), USER_INFO);
 cards.add(createEnrollmentPanel(), ENROLLMENT);
 setLayout(new BorderLayout());
 add(cards, BorderLayout.CENTER);
 JPanel enrol = new JPanel();
 enrol.add(new JLabel("Enrollment"));
 return enrol;
 JPanel userAgree = new JPanel();
 userAgree.add(new JLabel("User Agreement"));
 return userAgree;
 cardlayout.show(cards, key);

代码示例来源:origin: stackoverflow.com

public void switchCard(){
  contentPanel.setLayout(new CardLayout());
  CardLayout cl = (CardLayout) contentPanel.getLayout();
  cl.show(contentPanel, PLAY_ID);
}

代码示例来源:origin: stackoverflow.com

public class View extends JPanel {

  private CardLayout layout;

  public View(Controller controller, JComponent... subviews) {
    layout = new CardLayout();
    setLayout(layout);

    for (int index = 0; index < subviews.length; ++index) {
      JButton changeButton = new JButton("Change");
      changeButton.addActionListener(controller);
      subviews[index].add(changeButton);
      add(subviews[index], "View" + index);
    }
  }

  public void setSubview(int index) {
    layout.show(this, "View" + index);
  }

}

代码示例来源:origin: stackoverflow.com

final String IMAGES_PANEL = "Images Panel";
final String CONTROL_PANEL = "Control Panel";
CardLayout cardLayout;
JPanel cards;

//Where the components controlled by the CardLayout are initialized:
//Create the "cards".
JPanel card1 = new JPanel();
...
JPanel card2 = new JPanel();
...

//Create the panel that contains the "cards".
cardLayout = new CardLayout();
cards = new JPanel(cardLayout);
cards.add(card1, IMAGES_PANEL);
cards.add(card2, CONTROL_PANEL);
...
//Show images panel
cardLayout.show(cards,IMAGES_PANEL);
...
//Show control panel
cardLayout.show(cards, CONTROL_PANEL);

代码示例来源:origin: stackoverflow.com

MainMenu main = new MainMenu();
JPanel panel = new JPanel();
CardLayout card = new CardLayout();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().add(panel, BorderLayout.CENTER);
  card.show(panel, x);

代码示例来源:origin: stackoverflow.com

initComponents();
cards = new JPanel(new CardLayout());
add(cards);
setVisible(true);
cl.show(cards, cName);

代码示例来源:origin: stackoverflow.com

import java.awt.CardLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public @SuppressWarnings("serial")
class SwappingComponent extends JPanel {
  private static final String SHOW = "show";
  private static final String HIDE = "hide";
  JComponent component;
  CardLayout cardLayout = new CardLayout();

  public SwappingComponent(JComponent component) {
    setLayout(cardLayout);
    this.component = component;
    add(component, SHOW);
    add(new JLabel(), HIDE);
  }

  public JComponent getComponent() {
    return component;
  }

  public void showComponent(boolean show) {
    String key = show ? SHOW : HIDE;
    cardLayout.show(this, key);
  }

}

代码示例来源:origin: stackoverflow.com

static CardLayout cl = new CardLayout(); //handles panel switching
     public void run() {
        frame = new JFrame();
        frame.setDefaultCloseOperation(3);
        frame.setLayout(cl);
   cl.show(frame.getContentPane(), name);
   frame.pack();

代码示例来源:origin: stackoverflow.com

bg.add( highScores );
JPanel buttons = new JPanel(new 
  FlowLayout(FlowLayout.CENTER, 5, 5));
buttons.add( game );
buttons.add( highScores );
JPanel gui = new JPanel(new BorderLayout(5,5));
gui.add(buttons, BorderLayout.SOUTH);
final CardLayout cl = new CardLayout();
final JPanel cards = new JPanel(cl);
gui.add(cards);
cards.add(new JLabel("Level 1"), "game");
  public void actionPerformed(ActionEvent ae) {
    if (game.isSelected()) {
      cl.show(cards, "game");
    } else {
      cl.show(cards, "scores");

代码示例来源:origin: stackoverflow.com

MyPanel myPanel = null;
public GUI(){
  intitComponents();
  jPanelX.setLayout(new CardLayout());
  jPanelX.add(new JPanel(), "emptyPanel");
  myPanel = new MyPanel();
  jPanelX.add(myPanel, "myPanel");
}

...
private void jButtonXActionPerformed(java.awt.event.ActionEvent e) {
  CardLayout layout = (CardLayout)jPanelX.getLayout();
  layout.show(jPanelX, "myPanel");
}

代码示例来源:origin: stackoverflow.com

private JButton optionalButton;

private void buildWindow() {
  // ...

  optionalButton = new JButton("Optional Action");

  JPanel optionalButtonPanel = new JPanel(new CardLayout());
  optionalButtonPanel.add(optionalButton, "BUTTON");
  optionalButtonPanel.add(new JLabel(), "BLANK");

  // ...
}

private void setOptionalButtonVisible(boolean visible) {
  Container optionalButtonPanel = optionalButton.getParent();
  CardLayout layout = (CardLayout) optionalButtonPanel.getLayout();
  layout.show(optionalButtonPanel, visible ? "BUTTON" : "BLANK");
}

代码示例来源:origin: stackoverflow.com

private JLabel label = new JLabel();
private JTextField textField = new JTextField(COLUMNS);
private CardLayout cardLayout = new CardLayout();
  add(label, LABEL);
  add(textField, TEXT_FIELD);
  @Override
  public void mouseEntered(MouseEvent e) {
    cardLayout.show(SwapPanel.this, TEXT_FIELD);
  public void mouseExited(MouseEvent e) {
    label.setText(textField.getText());
    cardLayout.show(SwapPanel.this, LABEL);

代码示例来源:origin: stackoverflow.com

CardLayout cardPanelLayout = new CardLayout();
cardPanel.setLayout(cardPanelLayout);
...
cardPanelLayout.show("Throughput Graph");

代码示例来源:origin: stackoverflow.com

private JLabel jl1, jl2;
private JButton btn1, btn2;
private CardLayout cardLayout = new CardLayout();
      cardLayout.show(cardPanel, "1");
  btn2 = new JButton("Show Card 2");
  btn2.addActionListener(new ActionListener() {
      cardLayout.show(cardPanel, "2");
    public void run() {
      CardLayoutTest frame = new CardLayoutTest();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

//make it a sub class of JPanel for easier implementation. 
public class Cell extends JPanel{

  public  Cell(){

    JPanel firstPanel = new JPanel();
    //add a lable just so something is displayed
    firstPanel.add(new JLabel(("Panel 1"))); 
    JPanel secondPanel = new JPanel();
    JPanel thridpanel = new JPanel();

    CardLayout cardLayout = new CardLayout();
    /* assign the card layout */
    setLayout(cardLayout);

    /* add the different panels to the container panel and show the initial one */
    add(firstPanel, "firstPanel");
    add(secondPanel, "secondPanel");
    add(thridpanel, "thridpanel");
    cardLayout.show(this, "firstPanel");
  }
}

代码示例来源:origin: stackoverflow.com

JPanel panelCSV, panelExcel, panelDatabase;
CardLayout cardLayout = new CardLayout();
JPanel pagePanel = new JPanel(cardLayout);
pagePanel.add(panelCSV, "CSV");
pagePanel.add(panelExcel, "Excel");
pagePanel.add(panelDatabase, "Database");

public void btnContinueActionPerformed(ActionEvent e) {
  if ( rbCSV.isSelected() ) {
    cardLayout.show(pagePanel, "CSV");
  } else if ( rbExcel.isSelected() ) {
    cardLayout.show(pagePanel, "Excel");
  } else if ( rbDatabase.isSelected() ) {
    cardLayout.show(pagePanel, "Database");
  } else {
    // ....
  }
}

代码示例来源:origin: stackoverflow.com

private static final JPanel cards = new JPanel(new CardLayout());
private static final JComboBox combo = new JComboBox();
private final String name;
  this.setPreferredSize(new Dimension(320, 240));
  this.setBackground(new Color(random.nextInt()));
  this.add(new JLabel(name));
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  for (int i = 1; i < 9; i++) {
    CardPanel p = new CardPanel("Panel " + String.valueOf(i));
    combo.addItem(p);
    cards.add(p, p.toString());
  JPanel control = new JPanel();
  combo.addActionListener(new ActionListener() {
      JComboBox jcb = (JComboBox) e.getSource();
      CardLayout cl = (CardLayout) cards.getLayout();
      cl.show(cards, jcb.getSelectedItem().toString());
  control.add(combo);
  f.add(cards, BorderLayout.CENTER);
  f.add(control, BorderLayout.SOUTH);
  f.pack();
  f.setLocationRelativeTo(null);
  f.setVisible(true);

代码示例来源:origin: sing-group/GC4S

private JComponent getWizardMainPanel() {
  wizardMainPanel = new JPanel();
  wizardMainPanelLayout = new CardLayout();
  wizardMainPanel.setLayout(wizardMainPanelLayout);
  this.steps.forEach(s -> {
    wizardMainPanel.add(new WizardStepPanel(s));
  });
  this.wizardMainPanelLayout.show(wizardMainPanel, steps.get(0).getStepTitle());
  return wizardMainPanel;
}

代码示例来源:origin: stackoverflow.com

CardLayout myCardLayout = new CardLayout();
JPanel cardHolderPanel = new JPanel(myCardLayout);

// here add items to the JList and the cardHolderPanel, using the same String
// added to the JLabel as the key 2nd parameter to the add(...) method

// elsewhere...
public void valueChanged(ListSelectionEvent e) {
 String selection = stepList.getSelectedValue().toString();
 myCardLayout.show(cardHolderPanel, selection);
}

代码示例来源:origin: stackoverflow.com

final JPanel mainPanel=new JPanel();
 JPanel panelOne=new JPanel();
 JPanel panelTwo=new JPanel();
 final CardLayout card=new CardLayout();
 mainPanel.setLayout(card);
 mainPanel.add(panelOne, "one"); // id one refers panelOne
 mainPanel.add(panelTwo, "two"); // id two refers panelTwo
 panelOne.add(new JLabel("first panel"));
 JButton btn1=new JButton("Show second");
 panelOne.add(btn1);
 btn1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){
 card.show(mainPanel, "two"); // shows panelTwo
 }});
panelTwo.add(new JLabel("second panel"));
 JButton btn2=new JButton("Show First");
 panelTwo.add(btn2);
 btn2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){
 card.show(mainPanel, "one"); // shows panelOne
 }});

相关文章