Setting multiple JLabels
Hi,
I have a SWING Application which uses eight JLabels in a frame to display some data. When "resetting" the data each label should display zero.
Is there a better way than calling setText() on each JLabel (what I have in mind is something like
int i, x , y ,z = 0;
Hi,
setText() is the only option but to make it easier you could use an array of JLabel.
Phil
Similar Messages
-
Hi all, in my program I need to make a new JLabel at every clicked mouse location. My code for adding the JLabel looks like this:
// "lbl" is the name of my JLabel.
lbl = new make();
//make JLabel
class make extends JLabel
public make()
super("");
//set location of JLabel
lbl.setFont(font);
lbl.setBounds(x-font_size,y-font_size,font_size,font_size+3);
lbl.setForeground(c);Now I am new to java so I am not sure if this is the best way of adding multiple JLabels but the real problem is that so far I can't figure out how to refer to each individual JLabel that I create with the "make" class. What I need to be able to do is get the individual locations of each JLabel the user adds but sense each JLabel is to my knowledge named all the same (lbl). So is there a way to refer to each of these JLabels individually?
Any help would be great thanks.For example here's a small app that allows JLabel placement in a JPanel and into an ArrayList. It hen uses the references in the array list to set all the labels to a randomly chosen color every 2 seconds:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.Timer;
public class AddLabelOnClick {
// Color array used by Timer to select a random Color
private static final Color[] COLORS = {
Color.white, Color.red, Color.orange, Color.yellow,
Color.green, Color.blue, Color.pink, Color.cyan, Color.magenta
private static final Dimension APP_SIZE = new Dimension(600, 600);
// change Color every TIMER_DELAY milliseconds
private static final int TIMER_DELAY = 2000;
// mainPanel holds all the JLabels and the MouseListener
private JPanel mainPanel = new JPanel();
// the LIST of JLabels
private List<JLabel> labelList = new ArrayList<JLabel>();
private int labelCount = 0;
private Color currentLabelColor = COLORS[0];
private Random random = new Random();
public AddLabelOnClick() {
mainPanel.setPreferredSize(APP_SIZE);
// make panel null so we can use absolute positioning to add labels
mainPanel.setLayout(null);
mainPanel.setBackground(Color.darkGray);
mainPanel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
myMousePressed(e); // mouselistener method
// Timer changes label color to a randomly chosen color in the
// COLORS array.
new Timer(TIMER_DELAY, new ActionListener() {
public void actionPerformed(ActionEvent e) {
// select random color
currentLabelColor = COLORS[random.nextInt(COLORS.length)];
// iterate through the labelList changing the color of
// each JLabel as we do so.
for (JLabel label : labelList) {
label.setForeground(currentLabelColor);
}).start();
// my mouselistener method
private void myMousePressed(MouseEvent e) {
// create a new JLabel
JLabel label = new JLabel("Label " + labelCount);
label.setForeground(currentLabelColor); // set its color
label.setLocation(e.getPoint()); // place at mouse point
label.setSize(label.getPreferredSize()); // set size
mainPanel.add(label); // add label to the main JPanel
labelList.add(label); // add label to the ArrayList
labelCount++; // increase our counter
mainPanel.repaint(); // repaint the main panel so label will show
public JComponent getComponent() {
return mainPanel;
// create our GUI
private static void createAndShowUI() {
JFrame frame = new JFrame("AddLabelOnClick");
// create our class and then add the mainPanel to the
// JFrame, frame
frame.getContentPane().add(new AddLabelOnClick().getComponent());
// exit program when JFrame is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// to set the size of the main panel
frame.pack();
// center the app on the screen
frame.setLocationRelativeTo(null);
// show the app
frame.setVisible(true);
// start our GUI in a Swing thread-safe manner
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
createAndShowUI();
} -
I have an Apple ID with a single e mail address. I want to set multiple addresses in the same ID. Can I? If so how?
Howdy there johnzcarp,
As I understand it you want to have more than 1 email address under your Apple ID. You can have what are called Alternate Email addresses associated with your Apple ID and this article will help you get those setup:
Manage your Apple ID primary, rescue, alternate, and notification email addresses
Alternate email address
You can add one or more alternate email addresses for use with Apple services such as Game Center, FaceTime, Find My Friends, iMessage, and OS X notifications.
Go to My Apple ID (appleid.apple.com).
Select “Manage your Apple ID” and sign in.
Add an alternate address:
Select Add Email Address, then enter your alternate address. Apple will send a verification email to that address. Didn't receive the email?
Follow the instructions in the email to verify the address.
Edit an alternate address:
Select Edit next to the address, then enter the new address. Apple will send a verification email to that address. Didn't receive the email?
Follow the instructions in the email to verify the address.
Delete an alternate address: Select Delete next to the address.
Thank you for using Apple Support Communities.
Take care,
Sterling -
How to set multiple senders for one account
Hi all,
I have a BIS account with my provider and a paid gmail account which collect for me mails from different address. Is it possible to set multiple senders for this account, thus it seems that I'm replying from one of these address and not only from my google address? In fact, it's important for me also that all mails come out from the same SMTP server (google).
Thanks in advance.
Best regards,
PierluigiFor the BlackBerry to "send using" a specific email account, it must be set up on your BIS account as an email account, otherwise, you can send from that account.
You can do that, and then block ALL incoming emails from those accounts, and allow only incoming mail from your one Gmail account, if you desire.
1. If any post helps you please click the below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!
3. Install free BlackBerry Protect today for backups of contacts and data.
4. Guide to Unlocking your BlackBerry & Unlock Codes
Join our BBM Channels (Beta)
BlackBerry Support Forums Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
How to set multiple alarms on E90?
Hi guys,
I want to set multiple alarms on a 24 hour period of the same day, please give hints on how this can be done, on my pervious handset I was able to set alarms for multiple dates & times.
Solved!
Go to Solution.Does the E90 not have the same multiple alarm features as the N95 & N82?
Go into the clock, then press right for alarms. Then press Options > New Alarm and set it for the correct day and time. Then repeat the process to set mutiple alarms for the same day. -
How to set multiple values in one context-attribute
Hi all,
Anybody knows a possibility to set multiple Values to a context-attribute?
I know it how to get it with the following code:
String break[]= request.getParameterValues("break");
Now I want to do something like:
request.setParameterValues(break[no]);
where no is a counter in a loop.
With the Method setAttribute(), I overwrite the previous inserted value.
Thanx
RobertI have not explizit declared break as an array.
It is the Context- Attribute I want to send. I thaught that I can use it as an array in the same way I can do it when I send Data from an HTML- Form (with multiple values) to an servlet.
I don't know how to declare the Attribute explizit as an array.
that it is you wanted to know?
I think my main problem is to get an array from the servlet to the jsp. Is there an other possibility (other than via Context-Attributes) to do that?
thanx
robert -
How to set multiple styles on a single component in flex ?
Hi ,
I would like to know how to set multiple styles on a single component in flex.
Can anyone give me an example as to how to set multiple styles for a single component ?
Thanks ,
Regards,
AjanthaHi tuliptaurus,
You can setStyleName property for chnaging the external css dynamically by using the setStyle() method ...
btn.setStyle("styleName","blendButtonSkinOther");
You can change the external css by using the styleaName property with setStyle method..the line in blue..where blendButtonSkinOther is another css class..
blendButtonSkin {
fontFamily: Arial;
fontSize: 11;
color: #F1F1F1;
textRollOverColor: #F1F1F1;
textSelectedColor: #F1F1F1;
horizontal-align:center;
width:150;
height:30;
cornerRadius:5;
upSkin:ClassReference('assets.skins.BlendButtonSkin');
downSkin:ClassReference('assets.skins.BlendButtonSkin');
overSkin:ClassReference('assets.skins.BlendButtonSkin');
disabledSkin:ClassReference('assets.skins.BlendButtonSkin');
selected-up-skin: ClassReference('assets.skins.BlendButtonSkin');
selected-down-skin: ClassReference('assets.skins.BlendButtonSkin');
selected-over-skin: ClassReference('assets.skins.BlendButtonSkin');
blendButtonSkinOther {
fontFamily: Arial;
fontSize: 11;
color: #F1F1F1;
textRollOverColor: #F1F1F1;
textSelectedColor: #F1F1F1;
horizontal-align:center;
width:150;
height:30;
cornerRadius:5;
upSkin:ClassReference('assets.skins.BlendButtonSkin');
downSkin:ClassReference('assets.skins.BlendButtonSkin');
overSkin:ClassReference('assets.skins.BlendButtonSkin');
disabledSkin:ClassReference('assets.skins.BlendButtonSkin');
selected-up-skin: ClassReference('assets.skins.BlendButtonSkin');
selected-down-skin: ClassReference('assets.skins.BlendButtonSkin');
selected-over-skin: ClassReference('assets.skins.BlendButtonSkin');
Thanks,
Bhasker Chari -
My old version of Firefox had the option for me to set multiple home pages. My hard drive recently failed and had to be replaced, so I had to install the newest version of Firefox. The only option I see when I go to tools, options, general is to set the one home page. (and maybe tabs) I would like to open several of the same pages every time I open my Firefox. Does anyone know how to get this back, or which version had this feature so I can downgrade to that particular version?
Also, I was wondering if there is a way to get the bookmarks I had on the old version back. I think they are lost forever, but if anyone knows, I would be thankful. I do still have the old hard drive, but the way it failed was actually when you tried to open any browser, the hard drive would go and blue screen, this is why the old hard drive had to be replaced. Thanks. :)So you mean you want to open new windows with the same page when you open Firefox?
[[How to set the home page#w_set-more-than-one-website-as-your-home-page|Set more than one website as your home page]] should help if you want to open multiple pages when you open Firefox.
As for recovering your bookmarks, you can try to plug that hard drive into a working computer, and then read [[Recovering important data from an old profile]] to copy your bookmarks from it. However, if it is failing you may not be able to do that. -
How to set multiple languages to each tab in JTabbedPane?
Hi!!!
Am trying to set two different languages to each tab in a tabbedpane. For each language i have maintained one file with unicodes. So, If any key has an empty value in that file, the value for the same key in other language file should be displayed for the tab.so, here the actual probem occured. it was showing some boxes instead of that tab title.Please give me a solution to set different languages (using setFont()) for a tabbedpane.
Thank you
MouryaHi!!!
First of all .. Thanks a lot for ur valuable time and suggestions. Coming to the topic... i have used all these unicodes. Could you please tell me that would it be possible to set multiple languages to a tabbedpane at a time? (in the context of missing of keys setting other language key to that missed one).
Thanks
Mourya
Edited by: sindhumourya on Oct 7, 2008 1:58 AM -
Updating/setting multiple values in lookup field through powershell
I'm trying to set multiple values to lookup column. I can get it to set one value but multiple values don't work
see below
[Microsoft.SharePoint.SPFieldLookupValueCollection] $itemValues = New-Object Microsoft.SharePoint.SPFieldLookupValueCollection
[Microsoft.SharePoint.SPFieldLookupValue] $lookupvalue = New-Object Microsoft.SharePoint.SPFieldLookupValue
$lookupvalue.LookupId = 1
$lookupvalue.LookupId = 2
$itemValues.Add($lookupvalue)
$CMRSItems["Event Type"] = $itemValues
$CMRSItems.Update()
I was expecting the LookupID 1 and 2 to update but it doesn't. When i specify LookupId = 1 it works
What am i doing wrong.
Thanks in AdvanceHi Patrick,
In your script above you're using the same object to set both ID's on. Setting the ID of $lookupvalue, then adding it to the lookupvaluecollection, before changing the ID value to 2, then adding that to the collection.
I wrote an article on setting fields using PowerShell, but it doesn't include multiple lookup values. It does contain multiple choice and taxonomy values though, which is a similar concept. It's here if you want to take a look: http://social.technet.microsoft.com/wiki/contents/articles/20831.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-powershell.aspx
Regards, Matthew
MCPD | MCITP
My Blog
View
Matthew Yarlett's profile
See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
Upload and Crop User Profile Photos -
How to set multiple styles on a tree component?
Hi. I really need help...i wanted to know hot do i set multiple styles on e tree component using actionscript2.0...i need to change color, font size and font weight...Thanks for the help in advance
You can use treeInstanceName.setStyle("stylename",value) to set individual properties, or you can create a CSSStyleDeclaration object and incorporate each of the new style values into this one object and then apply the object to the component.
-
How to set multiple ORACLE_HOME and ORACLE_SID, on Windows
How to set multiple ORACLE_HOME and ORACLE_SID, on Windows.
I have 5 oracle instances. Every time if i want to start up the services , I am manually setting the environment variable (ORACLE_HOME and ORACLE_SID) and starting the services one at a time.
Can we set multiple ORACLE_HOME and ORACLE_SID in Start->My computer-> properties-> advance-> Environment variable.
Thanks
NaveenHi ,
Can you please give me the link, for the doc you are referring to
Thanks
Naveen -
How to set multiple operating units in before report trigger
hi all
can any one help me out in getting clear in how to set multiple operating units in before report trigger in oracle report.
as we set single operating unit (mo_global.set_policy.context('S',81); as 81 is my operating unit).then who to set for multiple operating unit at run time.Sounds like eBusiness Suite, right? Better ask this in the appropriate forum.
-
Set multiple default properties
Hi,
I am trying to set multiple default values for a property (multiple,text and unrestricted)from admin tool on WLPS 3.2 with WLS 5.1.
The problem is that only first value is persisted in the database and the rest of the values are lost when the server is restarted??? I confirmed it by crosschecking the tables.
Any help is appreciated.
Thanks,
--RajitHi Rajit,
Are you using Service Pack 2 for WLCS 3.2? There was an issue (CR044075)
dealing with muli-valued properties that was fixed in SP 2. See the Release
Notes for more information:
http://e-docs.bea.com/wlcs/docs32/relnotes/relnotes.htm.
Regards,
Ginny
"Rajit Gulati" <[email protected]> wrote in message
news:3c90e355$[email protected]..
Hi,
I am trying to set multiple default values for a property (multiple,textand unrestricted)from admin tool on WLPS 3.2 with WLS 5.1.
>
The problem is that only first value is persisted in the database and therest of the values are lost when the server is restarted??? I confirmed it
by crosschecking the tables.
>
Any help is appreciated.
Thanks,
--Rajit -
Set multiple passwords for single PDF
Hi All,
Do it is possible to set multiple passwords for single PDF i.e) a single PDF can be accessed using predefined passwords. It would be great if any one could can help me .
Thanks
AugustineThank you.
Do you mean different IDs can be used for a single PDF and can make the PDF protected.
Regards
Augustine
Maybe you are looking for
-
ITunes Home Sharing not loading over VPN after upgrade to 10.10.2
Hey, all. For years I have used a VPN to stream my iTunes library from my home computer to my work computer (who wants to bring a drive around with them everywhere?). It works flawless on 10.8.5... Ever since I upgraded to 10.10.2 on my Mac Mini, th
-
Can i use hdd + SSD in my macbook pro 2011 ?
can i use hdd + SSD in my macbook pro 2011 ? cause i already had 750GB and now i am palnnin gto buy SSD to install my system on it and keep the 750Gb as a storge can i ?
-
Can't install itunes due to registry error
can't install itunes. could not open key...HKEY_Local_Machine\Software\Classes\.m4v\open with proglds.
-
Cfform format="flash" not loading
The Problem: When I load a file that contains ANY cfform tag with format="flash", all I get is a partially rendered object with a spinning clock for a pointer. Your initial reaction is probably "oh, thats just bad code"... but, read on.. the plot thi
-
SQL Developer 1.5 where are connections stored?
SQL Developer 1.5 where are connections stored?