Modify « JLabel « Java Swing Q&A





1. Modifying a GridLayout/Changing Labels    coderanch.com

import java.awt.*; import javax.swing.*; import java.awt.event.*; class Testing extends JFrame { public Testing() { setLocation(300,100); setDefaultCloseOperation(EXIT_ON_CLOSE); final JPanel p = new JPanel(new GridLayout(2,2)); for(int x = 0; x < 4; x++) p.add(new JLabel(new ImageIcon("test1.gif"))); getContentPane().add(p); pack(); p.addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent me){ Point pt = new Point(me.getX(),me.getY()); JLabel lbl = (JLabel)p.getComponentAt(pt); lbl.setIcon(new ImageIcon("test2.gif"));}}); } public static void main(String[] args){new Testing().setVisible(true);} } ...

2. Modifying JLabel within separate class    java-forums.org

I have been searching the net for an answer with no answer found. Basically, I am trying to display a chronometer by displaying it on a JLabel which is on a JFrame. I have a JFrame class named TimerFrame, and a separate class Timer, which holds all the methods and variables needed for the chronometer. The GUI has two buttons, start/stop ...