Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


JLabels


Hello all,  I have created an array of labels. Now I need to do getText for a particular Label. Pls. find my code below:-  Statement tt = con.createStatement();           String pName = "SELECT process from test.process where idprocess LIKE " + id;         ResultSet procName = tt.executeQuery(pName);          while(procName.next()){         process = procName.getString(1);         //procName.close();            JPanel panel = createPanel();         JLabel check = createColoredLabel(process);         JLabel stDt = createColoredLabel(String.valueOf(dtIn));         JLabel enDt = createColoredLabel(String.valueOf(dtOut));         JLabel eng = createColoredLabel(engName);         JLabel stat = createColoredLabel(totalCheck+"/"complCheck"-"+status);         panel.add(check, new Integer(id));         panel.add(stDt, new Integer(id));         panel.add(enDt, new Integer(id));         panel.add(eng, new Integer(id));         panel.add(stat, new Integer(id));         JButton button = createButton(String.valueOf(id));         panel.add(button, new Integer(id));         getContentPane().add(panel);            pack();            //System.out.println(process);         }               procName.close();  private JLabel createColoredLabel(String text) {         JLabel label = new JLabel(text);         label.setVerticalAlignment(JLabel.CENTER);         label.setHorizontalAlignment(JLabel.LEFT);         label.setOpaque(true);         label.setFont(new java.awt.Font("Tahoma", 0, 12));         label.setPreferredSize(new java.awt.Dimension(125, 20));         label.setBackground(new java.awt.Color(255, 255, 153));         //label.setBorder(javax.swing.BorderFactory.createEtchedBorder());         return label;     }  private JPanel createPanel() {         JPanel panel = new javax.swing.JPanel();          panel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));         panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());         return panel;     }  private JButton createButton(String tst) {         final String chkProc = tst;         JButton button = new JButton();         button.setFont(new java.awt.Font("Tahoma", 1, 11));         button.setText("Load");          return button;     }

shreenivasa wrote: I have created an array of labels. Not in the code you posted, you haven't.  Use code tags to post codes -- [code]CODE[/code] will display asCODE Or click the CODE button and paste your code between the {code} tags that appear.  To get better help sooner, post a [SSCCE|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.  Also read [http://catb.org/~esr/faqs/smart-questions.html]  db

My question is I have created a JLabels using while loop. How can I retrive Lable Name?

Are you asking for this:?  JLabel[] labels = //etc.. 			//init the labels labels[0].getText(); 

yes you are right. But I am using other method to create group of labels. Please see above code. Also I assigned a Text for each lable. Now I need to access based on label assigned.  How to do that?  ALso is it possible to name Jlabels with variable name?  ex   for ( i=0; i<5 i++) {  JLabel test+i = new JLabel("TEXT");  }  like this. I want to link "i" JLable variable.

is it possible to name Jlabels with variable name? No.  No. no and no.  Learn to use arrays instead of just talking about them  db  edit The Java&#8482; Tutorials: [Arrays|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html|Study this before you come back]  Edited by: Darryl.Burke

shreenivasa wrote: But I am using other method to create group of labels.  Plz post that method. I cant seem to find it.  ALso is it possible to name Jlabels with variable name?  ex   for ( i=0; i<5 i++) {  JLabel test+i = new JLabel("TEXT");  }  like this. I want to link "i" JLable variable.  Thats what you use arrays for..  JLabel[] test = new JLabel[5]; for ( i=0; i<test.size() i++) { 	test[i] = new JLabel("TEXT"); }   Edited by: prigas on May 9, 2008 4:48 AM

Ok. Understood, But this works on fixed labels. But i need to create a dynamic labels for example. In following case i am reading a some names from SQL I need to create a 5 lables for each name.  I need to assign a JLable variable as "name"+chk, "name"+stDt etc. so I can retrive label name like this. "name"+chk.getText();  I know syntax is wrong. But is there any way to getText from following code.  Statement tt = con.createStatement();           String pName = "SELECT process from ucam.process where idprocess LIKE " + id;         ResultSet procName = tt.executeQuery(pName);          while(procName.next()){         process = procName.getString(1);         //procName.close();           JPanel panel = createPanel();         JLabel check = createColoredLabel(process);         JLabel stDt = createColoredLabel(String.valueOf(dtIn));         JLabel enDt = createColoredLabel(String.valueOf(dtOut));         JLabel eng = createColoredLabel(engName);         JLabel stat = createColoredLabel(totalCheck+"/"complCheck"-"+status);         panel.add(check, new Integer(id));         panel.add(stDt, new Integer(id));         panel.add(enDt, new Integer(id));         panel.add(eng, new Integer(id));         panel.add(stat, new Integer(id));         JButton button = createButton(String.valueOf(id));         panel.add(button, new Integer(id));         getContentPane().add(panel);            pack();             validate();          //System.out.println(process);         }               procName.close();         tt.close();           }  			  idProc.close();  			con.close();

You already got answers for every question - they won't change if you ask again.  1. Use CODE-Tags to post your code 2. Learn how to use Arrays  There is no need to dynamically generate variable-names.  Edited by: Stromberg on May 9, 2008 5:31 AM

And if you need a variable length array, use ArrayList.  db


Related Links

variable as a method
Vector generics with Lotus Notes View
OpenExternalApp doesn't work!
installed java and deleted the files---NOT ABLE TO INSTALL java AGAIN
cannot execute binary file. Classpath issue
XML to tree structure
execute java file at different directory
control wait time for a method call
cannot find symbol constructor CdCollection()
why some exceptions does not have to be explicitly declared "throws"
2 question different topics.
Collecting Multiple lines of input
Why does interfaces allow class definitions within them
Which toString() method does System.out.println() call?
Programing confusion
Straightforward way to use JSP and Servlet to get and display ResultSet