Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 06-24-2008, 03:57 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
You have mess somewhere in the grid. I'll try to find it. But not now.
Sir i am try to fiend out but still i havn't found.So plz help me
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 06-25-2008, 06:31 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
In most of the cases I'm avoiding GridLayouts. Because component adjusting is difficult. I have to add empty controls(empty labels) to make blank spaces. That mean I need to use more components.

GroupLayout is bit easier to use. Here is a simple example. Only change you have to do is, link with your parent dialog.

Code:
import java.awt.event.*; import javax.swing.*; /** * * @author Eranga Tennakoon */ public class Demo extends JFrame { private JPanel jPanel1; private JButton jButton1; private JLabel jLabel1; public Demo() { jPanel1 = new JPanel(); jButton1 = new JButton("OK"); jLabel1 = new JLabel("your label goes here"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent evt) { formWindowOpened(evt); } }); GroupLayout jPanel1Layout = new GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(139, 139, 139) .addComponent(jButton1)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(126, 126, 126) .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE))) .addContainerGap(151, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(63, 63, 63) .addComponent(jLabel1) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE) .addComponent(jButton1) .addGap(130, 130, 130)) ); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); } private void formWindowOpened(WindowEvent evt) { ImageIcon imageBack = new ImageIcon("images/master03_background.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0, 0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); jPanel1.setOpaque(false); setContentPane(jPanel1); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Demo().setVisible(true); } }); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #23 (permalink)  
Old 06-25-2008, 06:32 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
If you have any question on my code, ask me. I'll explain what's going on.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #24 (permalink)  
Old 06-25-2008, 08:18 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
If you have any question on my code, ask me. I'll explain what's going on.
Sir i am geting error
Code:
GroupLayout and LayoutStyle
Error is

Code:
GroupLayout cannot be resolved LayoutStyle cannot be resolved
i try to add import static javax.swing.GroupLayout.Alignment.*; this but is not accepting.
Bookmark Post in Technorati
Reply With Quote
  #25 (permalink)  
Old 06-25-2008, 08:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
It can't happened. My code working fine. I hope you added two import statements too. Add each library separately and try.

Code:
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.LayoutStyle; import javax.swing.WindowConstants;
Other than a mistake of you made in import packages, that code is working fine.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #26 (permalink)  
Old 06-25-2008, 08:52 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
It can't happened. My code working fine. I hope you added two import statements too. Add each library separately and try.

Code:
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.LayoutStyle; import javax.swing.WindowConstants;
Other than a mistake of you made in import packages, that code is working fine.
Sir i add all import package but error is showing on
Code:
import javax.swing.GroupLayout; import javax.swing.LayoutStyle;
Both are showing red marks.
Bookmark Post in Technorati
Reply With Quote
  #27 (permalink)  
Old 06-25-2008, 08:54 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
It can't happened. My code working fine. I hope you added two import statements too. Add each library separately and try.

Code:
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.LayoutStyle; import javax.swing.WindowConstants;
Other than a mistake of you made in import packages, that code is working fine.
here i code sir
Code:
import java.awt.event.*; import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.LayoutStyle; import javax.swing.WindowConstants; /** * * @author Eranga Tennakoon */ public class Demo extends JFrame { private JPanel jPanel1; private JButton jButton1; private JLabel jLabel1; public Demo() { jPanel1 = new JPanel(); jButton1 = new JButton("OK"); jLabel1 = new JLabel("your label goes here"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent evt) { formWindowOpened(evt); } }); GroupLayout jPanel1Layout = new GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(139, 139, 139) .addComponent(jButton1)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(126, 126, 126) .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE))) .addContainerGap(151, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(63, 63, 63) .addComponent(jLabel1) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE) .addComponent(jButton1) .addGap(130, 130, 130)) ); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); } private void formWindowOpened(WindowEvent evt) { ImageIcon imageBack = new ImageIcon("images/master03_background.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0, 0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); jPanel1.setOpaque(false); setContentPane(jPanel1); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Demo().setVisible(true); } }); } }
Bookmark Post in Technorati
Reply With Quote
  #28 (permalink)  
Old 06-25-2008, 09:04 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes this code working fine. I don't know what happened on your side. For me this is working fine.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #29 (permalink)  
Old 06-25-2008, 09:11 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Yes this code working fine. I don't know what happened on your side. For me this is working fine.
sir error in

Code:
import javax.swing.GroupLayout; import javax.swing.LayoutStyle;
How can i solve it sir..PLz sir help me
Bookmark Post in Technorati
Reply With Quote
  #30 (permalink)  
Old 06-25-2008, 09:15 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Which JDK version you used?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #31 (permalink)  
Old 06-25-2008, 09:22 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Which JDK version you used?
JDK 1.4 and ID MyEclipse
Bookmark Post in Technorati
Reply With Quote
  #32 (permalink)  
Old 06-25-2008, 09:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Oh dear that's the problem you have. Those two layouts supported from 1.6. So my advice is used the latest one. Update your JDK package. See you still use 1.4, too old.

Use the latest, then everything is fine. If you don't have update it, all the time mess with my code in the future.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #33 (permalink)  
Old 06-25-2008, 09:39 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Oh dear that's the problem you have. Those two layouts supported from 1.6. So my advice is used the latest one. Update your JDK package. See you still use 1.4, too old.

Use the latest, then everything is fine. If you don't have update it, all the time mess with my code in the future.
ok sir i Update then i will told you...
Bookmark Post in Technorati
Reply With Quote
  #34 (permalink)  
Old 06-25-2008, 09:52 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
It's better if you can update through your IDE. If not after updating you may have do more works. You use Eclipse right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #35 (permalink)  
Old 06-25-2008, 11:03 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
It's better if you can update through your IDE. If not after updating you may have do more works. You use Eclipse right?
Sir after update same problem come..
Bookmark Post in Technorati
Reply With Quote
  #36 (permalink)  
Old 06-25-2008, 11:04 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ya, I'm expecting that. What happened.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #37 (permalink)  
Old 06-25-2008, 11:06 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Ya, I'm expecting that. What happened.
Nothing sir after updation same error come.
Code:
import javax.swing.GroupLayout; import javax.swing.LayoutStyle;
Bookmark Post in Technorati
Reply With Quote
  #38 (permalink)  
Old 06-25-2008, 11:15 AM