jlabel

How to find JLabel that was clicked and show ImageIcon from it?

风格不统一 提交于 2019-12-12 07:28:49
问题 Here is my code. I want to know which l was clicked and then in a new frame, display that ImageIcon. The e.getSource() is not working... final JFrame shirts = new JFrame("T-shirts"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); for (int i = 1; i < 13; i++) { l = new JLabel(new ImageIcon("T-shirts/"+i+".jpg"), JLabel.CENTER); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); l.setFont(l.getFont().deriveFont(20f)); panel.add(l); }//end of for loop panel

Changing a label through a button (Java/Swing issue)

删除回忆录丶 提交于 2019-12-12 05:15:05
问题 newbie programmer here: I just made my first button. I want the button to change the label "Hello World!" to "Hello Universe!". I tried searching for ways to change the label through public void actionPerformed(ActionEvent e) , but failed to find any. If anybody would be kind enough to explain to me how to change the commented section in public void actionPerformed(ActionEvent e) to change the label, please explain! Thanks! My code: package game; import java.awt.*; import java.awt.event.*;

How do I display something I enter in a JOptionPane on the JFrame?

送分小仙女□ 提交于 2019-12-12 04:46:32
问题 What I want to do is when I input something in JOptionPane, say, APPLES. I want to display it as APPLES in the JFrame. Now, if I want to input CATS next, it'll appear in the JFrame together with the APPLES. It should look like this: APPLES CATS And when I input more, it just displays and displays. The only way I know how to do it is to use setText for JLabel, but it's only displaying ONE word. How do I display ALL of the words I input? 回答1: but it's only displaying ONE word Hoping that you

Layering text over JLabel

一个人想着一个人 提交于 2019-12-12 04:46:15
问题 This is how I want my app to look like. Trouble is, if I drag the JLabel with the "Hello, I'm Myra" over another JLabel (whose icon is the speech bubble), rather than superimposing or layering, NetBeans shifts the JLabels to be adjacent. How do I superimpose ie. place the text JLabel on top of another JLabel? Do note, I'm using NetBeans. It doesn't allow me to edit much of the JFrame or JLabel code. 回答1: Netbeans won't let you add components to a JLabel , it doesn't see them as a valid

Java: Moving second rectangle using different keys with KeyListener

落爺英雄遲暮 提交于 2019-12-12 04:26:58
问题 I am making a little program where two rectangles drive around a race car track. When I run the program everything goes as planned and I can move the black rectangle around the track using the arrow keys. If I want to move the red rectangle using W,A,S,D, what should I do? import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class first extends JLabel implements ActionListener, KeyListener { Timer t = new Timer(5, this); double x = 0, y = 25, velx =

Setting JLabels in rows and placing the equivalent JTextField right next to it

一世执手 提交于 2019-12-12 04:24:22
问题 I am trying to create 4 JLabel components 4 JTextfield components for my Swing based application. I am adding these lables and text fields in one of the many panels of the application. The class for this panel is as follows: public class CustomerInfoPanel extends JPanel implements ActionListener { private Car[] carList; private CarSalesSystem carSystem; private int currentIndex = 0; private JLabel headingLabel = new JLabel("Enter your details and let us find a car for you"); private JLabel

Trying to move JLabels on a JPanel with GridLayout

随声附和 提交于 2019-12-12 04:04:46
问题 I am trying to make some JLabels switch places with eachother on a JPanel with GridLayout on key pressed. So far: 1. I can only make them react to a mouse click. 2. They can only switch places with the one above it and to its left. Note: 1. If I set movePlayer(1) it works. And switches a JLabel from the grid (8,7) with an image of the player with one of the JLabels with an image of a floor above it. However my problem is, when i set movePlayer(2) it gives me and index out of bouds exception.

How to set label text to JTextField input

雨燕双飞 提交于 2019-12-12 03:19:20
问题 I'm trying to get a user to input a name in one panel on CardLayout and for the input to then define a JLabels text in the next panel that it switches to. I used System.out.println(userName); to double check that it was picking up the text and it definitely is but I don't know how to get the 'user' text to be that of the JTextFields input. Full working code below: import java.awt.CardLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton;

Why does my JFrame not show my label

你。 提交于 2019-12-12 02:59:19
问题 I have this loadpanel to show to the user when my program is exporting the video. So when the export button is clicked, I do this: loadframe = new LoadFrame("Video Exporteren..."); This creates the dialog and shows it on the screen. Yet, it takes about 5 seconds before the actual label on the dialog is shown. Can anyone tell me why. Thanks public LoadFrame(String operation) { mainloadframe = new JDialog(); JLabel operationlabel = new JLabel(operation); loadpanel = new JPanel(); mainloadframe

JLabel not showing up no matter what I do

回眸只為那壹抹淺笑 提交于 2019-12-12 02:22:03
问题 I have tried a ton of different things to try to get the JLabel to show but I don't understand why it is not working. I have tried resizing it, though that is not what i want to do, I have tried other classes, but I would prefer to stick with this one, and it is starting to get really frustrating. If you have any ideas please help. But please try to keep them simple and explain very clearly as I am still quite new to java. I have only been going for about three or four months. Here is my code