Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 50
  1. #21
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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

  2. #22
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

    Java 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);
                }
            });
        }
        
    }

  3. #23
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #24
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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
    Java Code:
    GroupLayout and LayoutStyle
    Error is

    Java Code:
    GroupLayout cannot be resolved
    LayoutStyle cannot be resolved
    i try to add import static javax.swing.GroupLayout.Alignment.*; this but is not accepting.

  5. #25
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    It can't happened. My code working fine. I hope you added two import statements too. Add each library separately and try.

    Java 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.

  6. #26
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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.

    Java 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
    Java Code:
    import javax.swing.GroupLayout;
    import javax.swing.LayoutStyle;
    Both are showing red marks.

  7. #27
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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.

    Java 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
    Java 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);
                }
            });
        }
        
    }

  8. #28
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes this code working fine. I don't know what happened on your side. For me this is working fine.

  9. #29
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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

    Java Code:
    import javax.swing.GroupLayout;
    import javax.swing.LayoutStyle;
    How can i solve it sir..PLz sir help me

  10. #30
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  11. #31
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Which JDK version you used?
    JDK 1.4 and ID MyEclipse

  12. #32
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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. ;)

  13. #33
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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...

  14. #34
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    It's better if you can update through your IDE. If not after updating you may have do more works. You use Eclipse right?

  15. #35
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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..

  16. #36
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  17. #37
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Ya, I'm expecting that. What happened.
    Nothing sir after updation same error come.
    Java Code:
    import javax.swing.GroupLayout;
    import javax.swing.LayoutStyle;

  18. #38
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  19. #39
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Now you wired me pal.

    What error you get. Can you send your error message here to see.
    yes this is a error

    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    
    	at Demo.main(Demo.java:82)

  20. #40
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Add an image to JFrame
    By Eranga in forum AWT / Swing
    Replies: 4
    Last Post: 02-01-2010, 03:09 PM
  2. Image Verification
    By peiceonly in forum Java Servlet
    Replies: 2
    Last Post: 04-04-2009, 07:38 AM
  3. How to display image ?
    By Birkoff in forum AWT / Swing
    Replies: 7
    Last Post: 06-09-2008, 07:58 AM
  4. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  5. 2D Array to image
    By fred in forum Java 2D
    Replies: 1
    Last Post: 07-24-2007, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •