jlabel

How to reset JLabel

拜拜、爱过 提交于 2019-12-24 03:35:09
问题 I am trying to reset an array of JLabels. There are images on the top of the labels so when i press a button the labels are supposed to be reset. I tried to do it like that for(int i=0; i<desks.length; i++) { desks[i].setText(""); rightPanel.add(desks[i]); } so if anyone have an idea it would be great.cheers. 回答1: this is one of possible ways int n = panel.getComponentCount(); if (n > 0) { Component[] components = panel.getComponents(); for (int i = 0; i < components.length; i++) { if

Swing menu item selection not setting content in the contentpane

回眸只為那壹抹淺笑 提交于 2019-12-24 02:45:25
问题 I have a Swing JFrame, which has a bunch of menu items. The below code tries but fails to set the content of the JFrame on selection of 'Add Address' menu item. JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setVisible(true); JMenuBar menuBar = new JMenuBar(); JMenu clientMenu = new JMenu("Client"); JMenuItem address = new JMenuItem("Add Address"); clientMenu.add(address); menuBar.add(clientMenu); address.addActionListener

JLabel changing values through setText but not updating on screen

寵の児 提交于 2019-12-24 02:09:14
问题 Well, I have been working on a piece of code for almost 2 days now and not able to resolve the issue. DESIRED BEHAVIOUR The following code is supposed to display 10 strings one by one (the next replacing the previous one) with a gap of aprox. 200 ms. q1 q2 q3 ...and so on upto q10 This display sequence starts when the user presses ENTER key. REFLECTED BEHAVIOUR The screen waits for aprox. 2 sec after pressing and then shows q10. Some more info The label stringText changes value during

Add a JLabel in the JTabbedPane header

纵饮孤独 提交于 2019-12-24 00:42:11
问题 I have this JDialog with a JTabbedPane: I just want to add a JLabel in the right-top area of the JTabbedPane so i can fire some events (e.g close the JDialog). And i don't want to make it a JFrame. PS: I know that is may be duplicated, but none of the responses give me a solution. 回答1: Well, actually that positioning inside JTabbedPane is not supported in Swing. But you can always make some street magic with layouts and layers: public static void main ( String[] args ) { try { UIManager

Java JLabel - add a unique identifier

落爺英雄遲暮 提交于 2019-12-24 00:19:34
问题 Is there anyway to add an ID or a unique identifier to a JLabel? Thanks all 回答1: JLabel has a setName method that is inherited from java.awt.Component. You could use this for an ID. 回答2: You can call Component.setName on it, or JComponent.putClientProperty , or subclass or use the JLabel object as a key is a Map of some sort. But probably the way to go is to keep hold of a reference to the original object, so you can write clean, direct code that doesn't have to look the component up. 来源:

Border Layout not working

旧时模样 提交于 2019-12-23 23:36:29
问题 I've been trying to setup this border layout for hours. I've looked up How to Use BorderLayout on the Java website but I still haven't gotten it. I've included my code below for review and to make it easier to see how I am trying to use the BorderLayout function. How do I setup a border layout on JL3? class GameStructure { private String []wordList = {"computer","java","activity","alaska","appearance","article", "automobile","basket","birthday","canada","central","character","chicken","chosen

JLabel refresh icon with updated image

拥有回忆 提交于 2019-12-23 19:48:35
问题 I'm trying to make an experiment in image manipulation. Basically I have an image that is continously updated by a timer and i display that image in a JLabel. My problem is that JLabel does'nt refresh the image. Here is my timer code: Timer timer = new Timer(200, new ActionListener() { public void actionPerformed(ActionEvent e) { count++; System.out.println("timer"); System.out.println(filename); ImageIcon icon = new ImageIcon(filename); label = new JLabel(); label.setIcon(icon); label

Updating message in JOptionPane

泄露秘密 提交于 2019-12-23 19:39:51
问题 I am trying to make a digital clock which displays the time in a JOptionPane. I've managed to display the time on the message dialog box. However, I can't figure out how to make it update the time at every second in the dialog box. This is what I currently have: Date now = Calendar.getInstance().getTime(); DateFormat time = new SimpleDateFormat("hh:mm:ss a."); String s = time.format(now); JLabel label = new JLabel(s, JLabel.CENTER); label.setFont(new Font("DigifaceWide Regular", Font.PLAIN,

Change the text of a JLabel - Beginner

纵然是瞬间 提交于 2019-12-23 19:02:57
问题 My code; package com.test; import java.awt.EventQueue; public class TestGU { private JFrame frame; private JLabel la; /** * Launch the application. */ public void mainM() { EventQueue.invokeLater(new Runnable() { public void run() { try { TestGU window = new TestGU(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public void redefine(String text){ la.setText(text); frame.repaint(); } /** * Create the application. */ public TestGU() { initialize(); } /**

why showing .GIF image increase memory continuously?

前提是你 提交于 2019-12-23 12:59:38
问题 i am showing simple code sample. I showed an gif image in a Jlabel . When run the programme, TASK manager shows that memory is increasing continuously. Why it happens? Edited: try this code please... on show glass button, glass panel is shown with gif image and a hide glass button in it and with that memory will be started increasing. On clicking hide glass button, glass panel will be hidden and memory increasing will b stopped. @mKorbel : I had debugged it, the constructor will be called