cardlayout

JFrame getLayout method does not return set cardLayout

我怕爱的太早我们不能终老 提交于 2019-12-24 13:15:59
问题 I am setting a CardLayout as the a JFrame's layout but when I call the getLayout method a border layout is returned. import java.awt.CardLayout; import javax.swing.JFrame; public class SSCCE { public static void main(String[] args) { JFrame frame = new JFrame(); CardLayout cl = new CardLayout(); frame.setLayout(cl); System.out.println(cl); System.out.println(frame.getLayout()); } } This is printed to console: java.awt.CardLayout[hgap=0,vgap=0] java.awt.BorderLayout[hgap=0,vgap=0] 回答1: JFrame

JPanel Won't Focus After Switching in CardLayout

℡╲_俬逩灬. 提交于 2019-12-24 09:47:05
问题 I am creating a Tetris clone as a personal project. In order to switch between the menus, I am using a CardLayout , but I have come across a problem. When I switch from one menu to the other, the focus does not transfer to the other JPanel . How can I fix this? Here is my JFrame: package com.cgp.tetris; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JPanel; public class TetrisFrame extends JFrame { private static

Get focus on a JTextField inside a CardLayout

佐手、 提交于 2019-12-23 22:44:28
问题 I have a JTextField inside a JPanel A which is a part of CardLayout . When this A gets shown, I want to set the focus automatically to the JTextField (i.e. the cursor is flashing in the text field so the user doesn't need to click on it to enable the input). I tried calling requestFocusInWindow() on the JTextField object at initialization, but that doesn't seem to work. Do I need to call this method every time when A gets displayed? Thanks. 回答1: Maybe you can try requestFocusInWindow() when

Java - CardLayout show() IllegalArgumentException

ⅰ亾dé卋堺 提交于 2019-12-23 04:51:37
问题 I have a problem with the CardLayout show method So I declare my CardLayout and apply it to my JPanel CardLayout cl = new CardLayout(); panel.setLayout(cl); Then I add a 2 panels into the CardLayout cl.addLayoutComponent(panel, "menuScreen"); cl.addLayoutComponent(panel1, "gameScreen"); I then have a JButton that when is clicked, I show the gameScreen public void mouseClicked(MouseEvent e) { if(e.getSource() == (startGame)) scenechange.show(panel,"gameScreen"); } The only problem is that it

JFrame whose content changes as we click on the different buttons

你。 提交于 2019-12-22 10:55:24
问题 I am using Java's Swing here to make a UI application. I have a created a JFrame, with some buttons. When I click on this button, I want a new JFrame with some different content at this place. However, I do not want a new JFrame to load here. One approach, I know is of setting the visbility of the second JFrame to be True in the actionPerformed(ActionEvent obj) method of the button in the first JFrame. But it again loads a new JFrame and I don't want that. public class FirstUI extends JFrame

Java: CardLayout switching between cards

試著忘記壹切 提交于 2019-12-22 08:59:15
问题 I've got class 'Frame' which extends JFrame and separetad JPanels : MainMenu and SinglePanel I am using CardLayout , but I've got problem when switching back to panels using buttonSingle and powrot buttons. So my question is how can I change/swap between cards using these buttons? My Frame class: public class Frame extends JFrame{ CardLayout cl = new CardLayout(); final MainMenu menuPanel = new MainMenu(); final SinglePanel singlePanel = new SinglePanel(); public Frame(){ setLayout(cl); add

How do I work with the Card Layout in the NetBeans GUI builder?

折月煮酒 提交于 2019-12-22 05:25:29
问题 Does anyone know how to work with the Card Layout in the NetBeans GUI builder tool? I want to show panels as per the JRadioButton selection, so I want to lay this out using the Card Layout. 回答1: Here is a very simple tutorial that might start you off in the right direction. I hope it is helpful. 回答2: The Sun tutorial seems a good place to start to learn about Card Layouts. Concerning NetBeans per se , simply assign the card layout to the component you wish to assign to (example a JPanel),

Parent container/panel for a CardLayout

孤人 提交于 2019-12-20 05:49:07
问题 How I can get the 'container' panel for any panel in CardLayout . That is, if a panel is a card in another 'container' panel, then how to get reference to this 'container' panel, from the card? Here's what i am doing:- public class LogInPanel extends javax.swing.JPanel implements ActionListener{ /** * Creates new form Panel2 */ private JPanel parentPanel; private CardLayout c1=null; public LogInPanel() { initComponents(); //c1=new CardLayout(); parentPanel=(JPanel)(SwingUtilities

A individual class for each Card in java swing CardLayout

久未见 提交于 2019-12-18 07:07:47
问题 For architecture and design purposes I would like to design my GUI with a class for each card in a Java Swing CardLayout. and then have a mainapp that builds the GUI. I am having trouble doing this right now. I would like to example have a class for the main menu with all the button locations etc. and then just instantiate that card and add it to the layout in another class. Does anyone know how to achieve this? 回答1: Perhaps you want to give your class that uses the CardLayout a public

Change size of JPanel using CardLayout

女生的网名这么多〃 提交于 2019-12-17 14:15:23
问题 is it possible to change the size of Jpanels when using Java CardLayout? 回答1: shoot, something like this where the component (here a JLabel rather than a JPanel) has it's preferredSize set, then place it in another JPanel that uses an appropriate layout, here GridBagLayout which with default settings will center the component, and add the GridBagLayout using JPanel to the CardLayout using panel:: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border