473,385 Members | 1,409 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,385 software developers and data experts.

GridLayout : Why this happens?

82
I have got a JLabel : label1 with an image.Then i add a GridLayout on the Label. Then i make a new label: label2 and i add it in the label1.Then i make a new label:label3 and when i add it goes down from the label2 and not near.Why this happens? Look and my pictures(especially the second)

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class GridLayoutDemo1 extends JFrame
  5. {
  6.     public static final int WIDTH = 468;
  7.     public static final int HEIGHT = 468;
  8.  
  9.     public static void main(String[] args)
  10.     {
  11.         GridLayoutDemo1 gui1 = new GridLayoutDemo1();
  12.         gui1.setVisible(true);
  13.     }
  14.  
  15.     public GridLayoutDemo1()
  16.     {
  17.         setSize(WIDTH, HEIGHT);
  18.         addWindowListener(new WindowDestroyer());
  19.  
  20.         Container content = getContentPane();
  21.  
  22.        ImageIcon icon1 = new ImageIcon("tes.jpg");
  23.  
  24.         JLabel label1 = new JLabel(icon1);
  25.  
  26.         content.add(label1);
  27.         label1.setLayout(new GridLayout(10, 10));
  28.  
  29.         JLabel label2 = new JLabel("First");
  30.         label1.add(label2);
  31.         JLabel label3 = new JLabel("Second");
  32.         label1.add(label3);
  33.  
  34.     }
  35. }


first picture with only label1

Mar 24 '08 #1
4 1801
r035198x
13,262 8TB
The first part of the specs for GridLayout has a detailed explanation for this.
Mar 25 '08 #2
kalar
82
Thanks !!!!
If i understand good the number of columns is ignored.
So i must fill the hole gridLayout whith 100 Labels. Then i can put what i want in any position i.e. in 99 . Am i right?
Mar 25 '08 #3
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1.         JLabel label1 = new JLabel(icon1);
  2.  
  3.         content.add(label1);
  4.         label1.setLayout(new GridLayout(10, 10));
  5.  
You are using a label as if it were a regular Container. Officially it is (because it
inherits from that class) but don't use it as such: the way it is intended to be
used is to display a single String and/or an Icon; on top of each other or next
to each other. Use a JPanel instead that uses that GridLayout.

kind regards,

Jos
Mar 25 '08 #4
kalar
82
You are using a label as if it were a regular Container. Officially it is (because it
inherits from that class) but don't use it as such: the way it is intended to be
used is to display a single String and/or an Icon; on top of each other or next
to each other. Use a JPanel instead that uses that GridLayout.

kind regards,

Jos
yes but i don't know how to insert an icon on JPanel(without draw it)? do you know?
I want first have a picture and over it put other smaller pictures(icons)
Mar 25 '08 #5

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

Similar topics

0
by: Kenneth | last post by:
Hi, I use VS.NET Enterprice Achitect 2002 version and when I try to create a page in gridlayout all font sizes goes banana in all 'Label' and 'RequiredFieldValidator' objects. TextBoxes,...
2
by: Just D. | last post by:
Who knows what should we include into aspx file to show some image as a background picture but only once at the top of the page? I don't want to add the Image control because even if it uses a...
10
by: tshad | last post by:
I was curious if MS_POSITIONING="GridLayout" is supported in the Body tag? I was running DW using a page with this in it and it says it isn't supported in the Body tag. It says "The...
1
by: conckrish | last post by:
Hi All.. Can u please explain me, what is the difference between FlowLayout and GridLayout and which one is best for DataGrid control?? Thanks!!
1
by: Tina | last post by:
I see that in VS.Net 2005, grid layout is no longer supported. I really liked gridlayout because I could put things exactly where I wanted them. How can we put things exactly where we want them...
1
by: Didje | last post by:
Hi, I am trying to create a grid which contains three rows, within each row there will be various buttons also in gridlayout. There are 20 buttons in the middle row, 3 in the top and 4 at the...
1
by: luqman | last post by:
How to set GridLayout and FlowLayOut in VS 2005 ? Best Regards, Luqman
2
by: kalar | last post by:
I want to ask something about swing. Can i set an icon ( it is a big picture) in JFrame and then add labels with GridLayout over the picture?What i want to do is : in my window i want to have a...
2
by: MiziaQ | last post by:
Is there a way to have an uneven (LARGER) horizontal gap between the 2nd and 3rd columns, using gridLayout, and leave the gaps between 1st, 2nd and 3rd and 4th the same (SMALLER)? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.