jlabel

Java - Change JLabel

孤街浪徒 提交于 2019-12-02 13:26:13
I have a class of buttons called Keys.java which returns a panel of buttons to the class called Control.java. I have a JLabel in Control.java, but what I want to do is change a JLabel when a button is pressed. How would you go about doing this? I have tried setting a string in Keys.java which changes based on the button and then setting the JLabel's text equal to the string but it doesn't seem to work. Any thoughts on how to achieve this? trashgod It may be that you are updating the wrong string or setting the corresponding label's text incorrectly. Both are required. In the example below

update jlabel text after opening jdialog

こ雲淡風輕ζ 提交于 2019-12-02 13:13:30
I have to query database to get data to write on JLabel and to accelerate opening dialog I have created JLabel with no text and set text after done a SwingWorker process but JLabel text doesn't be updated Is there any way to achieve this Here is my dialog's src code: package com.caisse.caisseFrame.dialogs; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Image; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.imageio.ImageIO

When I trigger my fireball creating, it resets my Character JLabel

此生再无相见时 提交于 2019-12-02 10:58:21
package clickrpg2; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.*; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.Timer; public class MainFrame extends javax.swing.JFrame implements ActionListener { static MainFrame mainFrame = new MainFrame(); static Hero hero = new Hero(); static JLabel fireballButton[] = new JLabel[1000000]; static int fireballTotal = 0; Timer timer = new Timer(10, this); public MainFrame() { addKeyListener(new KeyThing()); addMouseListener(new MouseThing()); initComponents(); } // <editor-fold defaultstate=

Get jDateChooser date to jLabel

心不动则不痛 提交于 2019-12-02 10:56:02
问题 This is my infernal problem. nowadays i'm trying to create my project according to my Degree. I already have added jcalender to my project in netbeans, and i already added jDateChooser to my jFrame. my problem is, when i chooseing a date from jDateChooser how will display this date on a jLabel. i tried to using jLabel1.setText(jDateChooser1); but in this case error will occur. http://imgur.com/nMa9JMw 回答1: First, you need to get the date from the component, something like... Date date =

How Do I Make These JLabels of JButtons invisible

青春壹個敷衍的年華 提交于 2019-12-02 10:39:28
问题 I have a class called BoardSquare that is an inherited class of JButton . Each of the BoardSquare objects is stored in an array BoardSquare[][] boardsquares . I have used the following code BoardSquare.boardSquares[j][i].add(new JLabel((j+1)+":"+(i+1))); to add labels to each of the squares in the array according to their coordinates. I need them to have these labels(I think) so that I can identify them and addActionListeners , etc. How do I make the JLabels invisible so they don't show up in

JLabel and JTextField setText is not update

怎甘沉沦 提交于 2019-12-02 10:32:26
I want to update jlabel and jtextfield with setText() method but it is not working. However, rest of the code is working. The code is below; btnDosyaSe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int kullaniciSecimi = jfc.showOpenDialog(null); if (kullaniciSecimi == JFileChooser.APPROVE_OPTION) { File fileName = jfc.getSelectedFile(); textField.setText(fileName.getPath()); islemSureci.setText("Veriler Okunuyor..."); try { ArrayList<ArrayList<String>>

JLabel over another JLabel not working

江枫思渺然 提交于 2019-12-02 10:19:17
I've been trying to put a JLabel over another one for my Roguelike. Unfortunaly, it doesn't seems to work. Here's my code so far : public void updateDraw(int direction){ int[] pos = Dungeon.getPos(); for(int i=pos[1]-(DISPLAY_Y_SIZE/2) ; i<pos[1]+(DISPLAY_Y_SIZE/2) ; i++){ for(int j=pos[0]-(DISPLAY_X_SIZE/2) ; j<pos[0]+(DISPLAY_X_SIZE/2) ; j++){ labelGrid[i-(pos[1]-(DISPLAY_Y_SIZE/2))][j-(pos[0]-(DISPLAY_X_SIZE/2))].setIcon(tiles[Dungeon.getMapTile(i,j)].getIcon()); } } labelGrid[DISPLAY_Y_SIZE/2][DISPLAY_X_SIZE/2].add(character); this.repaint(); } I've read some solutions to other problems,

several times change label text by clicking button in swing not work

好久不见. 提交于 2019-12-02 10:09:23
I need to change jlabel.text several times by one click button in swing. In this code i need set label text to start before dowork() function and set to in progress in middle and set it to end after dowork() (status type in jlabel and dowork has long time execution) : private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { status.setText("start"); try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(PelakInRFID.class.getName()).log(Level.SEVERE, null, ex); } status.setText("in progress"); dowork(); try { Thread.sleep(10000); } catch

How to properly refresh image in JFrame?

不羁的心 提交于 2019-12-02 10:06:55
This is a problem that disturbs me for few hours now and I'm not able to find a solution by myself... I've found similar topics all around the net, but I couldn't find exact same problem with well explained and as simple as possible solution. I've also looked at EDT and SwingWorker API docs, but it was far too complicated for me :( So, let's get to the point. I have a simple JFrame with JLabel inside, that consist of my image: private static class MyJLabel extends JLabel { private ImageIcon img = null; public MyJLabel(ImageIcon img) { super(); this.img = img; } @Override public void

How to change a cell icon of JList in run time

戏子无情 提交于 2019-12-02 09:59:07
How can I change a JLabel icon of only one JList cell(for example: clicking in JList)? I tried to access the JLabel getting with listCellRender but it don't works: @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListCellRenderer r = list.getCellRenderer(); JLabel comp = (JLabel) r.getListCellRendererComponent(list, list.getSelectedValue(), list.getSelectedIndex(), false, false); comp.setIcon(UIManager.getIcon("Tree.leafIcon")); } Can anyone give some idea? Thanks in advance! My code: import java.awt.*; import java.util.Arrays; import javax.swing.*;