473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Adding JLabel Component to flow layout by calling custom function is not working

I am adding multiple labels and text boxes in one form display using swing. Because the height width and the inter-spaces are consistent so I am using common function to add Labels and Text box.

A function accepting 3 argument : element to be added and the type of it(JLabel or JTexField) and the labels corresponding to which the current label need to be positioned
Expand|Select|Wrap|Line Numbers
  1.  
  2.          private void setCustomBounds(Object elemnt, String type, JLabel refLabel){
  3.         JLabel lbl;
  4.         JTextField txtField;
  5.         int xField, yField; // variables for x and y Co-ordinate to set bounds , Height and Width will be used from the variable set above
  6.  
  7.         System.out.println("Setting the bounds for "+type);
  8.  
  9.         //set Bounds(x,y) for Label
  10.         if (type.equalsIgnoreCase("label")){
  11.             lbl=((JLabel)elemnt);
  12.  
  13.             System.out.println("Setting label bounds with referen to above label");
  14.             xField=xAxis;
  15.             yField=refLabel.getY()+height+gap;  // need to get the y-axis Co-ordinate for the referenCe Label 
  16.                                             //and then add the height of that Component(beCause the values drawn in java are from top to bottom) 
  17.                                             // and add the gap between two elements
  18.                lbl.setBounds(xField, yField, width, height); // Setting the bounds for the Component
  19.                lbl.setFont(lblFont); // Setting the font as desCribed above in the variable
  20.                add(lbl);        //adding the Component to the layout
  21.                //revalidate();
  22.             //repaint();
  23.  
  24.         }
  25.  
  26.         //set Bounds(x,y) for TextFiled
  27.         if(type.equalsIgnoreCase("txtBox")){
  28.             txtField=((JTextField)elemnt);
  29.  
  30.             System.out.println("Setting TextField bounds with reference to beside label");
  31.             xField = xAxis+width+gap;       // xAxis + width define the right x-axis Co-ordinate for the referenCe Label
  32.             yField = refLabel.getY();       // as the left side Label will be on the same height so getY() will be enough
  33.             txtField.setBounds(xField, yField, width, height);   // Setting the bounds for the Component
  34.             add(txtField);   // add the Component to the Layout
  35.  
  36.         }        
  37.  
  38.  
  39.     }
  40.  
xAxis,yAxis,gap,height and width variable values has been defined privately

The 'setCustomBounds' function is being called from main function :

Expand|Select|Wrap|Line Numbers
  1. lbl_empid = new JLabel("Employee-ID");
  2.        // lbl_empid.setBounds(xAxis, lbl_title.getHeight() + lbl_title.getY() + gap, width, height);
  3.         //lbl_empid.setFont(lblFont);
  4.         //add(lbl_empid)
  5.  
  6.          setCustomBounds(lbl_empid, "label", lbl_title);
  7.  
  8.  
lbl_title is a label positioned at the top for which bounds has been defined already .

using above code I am unable to add the label to the display.
However, if the label is added without calling function, it is getting added.
Feb 7 '15 #1
0 1332

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: VB Programmer | last post by:
I have a custom menu usercontrol that is to go on the top of all my asp.net webforms. I was wondering, how can I use FLOW layout on a page that uses this user control? (The reason I need to do...
1
by: RobertH | last post by:
Been getting allot of complaints from users that everything is squashed and overlayed and fonts are overlapping into buttons etc.. etc... So i determine that grid layout is probably bad, 50% of the...
4
by: NWx | last post by:
Hi, I develop an ASP.NET app which should be used from Internet, so I don't have control over what browsers will be used. I don't want to target every possible users, so I don't really mind is...
6
by: Don Collins | last post by:
Can anyone point me to a white paper discussing the advantages / disadvantages to using “grid layout” vs. “flow layout” on webforms? I’m looking to address performance issues in particular.
0
by: Raghu Raman | last post by:
hi am using the flow layout inmy c#.net asp app.i am using a grid & a panel inside a table in two rows.I set visible =false to that grid sothat the panel moves up and occupies the grids'...
2
by: Andrew Chalk | last post by:
I have set a page to "flow layout". How do i now set it back to grid layout? Many thanks
4
by: VB Programmer | last post by:
I have user controls that I'm going to place on the form. There could be from 0 - 20. I want the user to be able to resize the window and have the controls relocate automatically, but like FLOW...
1
by: David Lozzi | last post by:
Howdy, I have a datalist which is displaying a list of categories and their associated sub categories in secondary datalists. Works great in a single column. Unfortunaly when i switch it to...
0
by: Smokey Grindel | last post by:
flow layout panel too slow? why is the flow layout panel so slow at drawing when you resize a form? when i make it fill docked place controls in it and resize it, it flickers like crazy! i turn on...
1
by: JDeats | last post by:
So I have a new WebForm created in VS.NET 2005 that's in the default "flow layout". I have a dropdown list box followed by HTML break- return <brtags and two two text boxes, below the text boxes I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.