jpanel

Modifying independent JPanels from the JFrame

淺唱寂寞╮ 提交于 2019-12-31 04:43:08
问题 I've got a JFrame with two separate JPanels. One of the JPanels is filled with JButtons while the other has a couple of text fields. I added mouse listeners to the buttons via the JFrame and I want to make it so that when an event is fired from the first JPanel, the text fields in the second JPanel are changed. The two panels have their own classes. How would I go about doing this? 回答1: Use MVC, Model-View-Control, separation of concerns. Have the Control, which holds your listeners, change

Positioning JLabel in JPanel below the image

时光总嘲笑我的痴心妄想 提交于 2019-12-31 04:04:26
问题 I want to move the Text below the image and shape in the given example. Please help me to do it. package test; import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class TestLabel extends JPanel { private Integer size = 70; private String name; private Image image; public TestLabel(Integer size, String name) { this.name =

Adding JPanel to JScrollPane

谁说胖子不能爱 提交于 2019-12-31 04:02:34
问题 I have a gui which has a Panel that contains a sequence of labels and TextFields and uses a spring layout(this is the mainPanel) and another Panel that just contains a button(buttonPanel). I am trying to make my mainPanel to have a vertical scrollbar as well. I would like to implement my GUI such that within the JFrame I have 2 panels. The mainPanel appears on the top of the frame and the buttonPanel appears below the mainPanel. My problem is I am not able to make the Panels appear such that

repaint JPanel with every click at JList

只愿长相守 提交于 2019-12-31 03:53:05
问题 everytime i click on a JList item, i need to clear + refresh my current panel & load another panel, returned via method 'populateWithButtons()'. temp is an int variable that stores what was clicked at the JList. How do i rectify the following? list_1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { //refresh + populate JPanel Food food = new Food(); JPanel panel2 = new JPanel(); JPanel pane11 = new JPanel(); panel2.add(panel1); panel1.validate();

Resizing a JPanel inside a JFrame

血红的双手。 提交于 2019-12-31 01:40:26
问题 I am new to Java, started learning swing and have a problem with resizing a JPanel inside a JFrame. I am following this tutorial: http://vincentramdhanie.blogspot.com/2009/11/cardlayout-with-netbeans.html because ultimately I am learning each of the different layouts and have come to the CardLayout now. In the above, there is a JPanel being used for a status panel. That is what I want to do as well, but when I drag a JPanel onto my blank JForm it takes up all the space and I don't see any

Resizing a JPanel inside a JFrame

主宰稳场 提交于 2019-12-31 01:40:05
问题 I am new to Java, started learning swing and have a problem with resizing a JPanel inside a JFrame. I am following this tutorial: http://vincentramdhanie.blogspot.com/2009/11/cardlayout-with-netbeans.html because ultimately I am learning each of the different layouts and have come to the CardLayout now. In the above, there is a JPanel being used for a status panel. That is what I want to do as well, but when I drag a JPanel onto my blank JForm it takes up all the space and I don't see any

JFrame, JPanel, paintComponent how to

旧时模样 提交于 2019-12-30 14:42:41
问题 Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp;

JFrame, JPanel, paintComponent how to

本小妞迷上赌 提交于 2019-12-30 14:42:12
问题 Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp;

Implementing CardLayout within a JFrame and switching cards based on specific button presses

谁说我不能喝 提交于 2019-12-30 13:35:16
问题 I've posted my code below. I have the simple task of creating a navigable GUI. I've spent the past few hours doing research on how to accomplish this, and this is the code that I've put together. Originally I wanted to perform the navigation without any layouts or anything. I need the home panel to display after the user clicks on the "login" button on the welcome panel. It displays the welcome card just fine, but when I get to the validateLogin method(which is activated when the login button

Multiple animations(threads) in a JPanel

风流意气都作罢 提交于 2019-12-30 12:22:54
问题 I am trying to code a board game in Java. I have 11 classes including Main. Board class which extends JPanel and draws the board image as well as the dice image. The class Player which extends JCoponent and implements Runnable(Thread). Every player instance is a pawn-animation that it is moving across the board. The player class draws the pawn on the board. Pattern How the code it looks like : Board b=new Board(); Player p=new Player(); b.add(p); JPanel panel=new JPanel(); panel.add(b); add