Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Some much needed help, and questions.

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Some much needed help, and questions.

    How would I prevent a JPane from resizing? I've tried Pane.setPreferred/.setMin and .setMax and neither work. Or am I doing something wrong?

    Also my problem with the filechooser is it is smushed in 3,1 is there a way I can get it fully into 3,1?

    package synch;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
     
    public class Synch extends JPanel {
     
     
     
     
     
     
     
     
        private JLabel targetLabel = new JLabel("Source");
        private JLabel sourceLabel = new JLabel("Target");
        private JButton browseButton = new JButton("Browse");
        private JButton browseButton1 = new JButton("Browse");
        private JButton copyButton = new JButton("Copy!");
        private JTextField textField = new JTextField(" ");
        private JTextField textField1 = new JTextField(" ");
        private JFileChooser fc = new JFileChooser();
     
        private JMenuItem Exit, oneWaySynch, twoWaySynch, Help, About, HelpMe;
     
     
     
     
     
     
        public Synch(){
            JFrame prog = new JFrame("Chris's file synchronization");
            prog.setSize(600,350);
            prog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            JMenuBar jmb = new JMenuBar();
            prog.setJMenuBar(jmb);
            JMenu fileMenu = new JMenu("File");
            jmb.add(fileMenu);
            fileMenu.add(oneWaySynch = new JMenuItem(" One way Synch "));
            fileMenu.add(twoWaySynch = new JMenuItem(" Two way Synch "));
            fileMenu.add(Exit = new JMenuItem("Exit"));
     
            JMenu helpMenu = new JMenu("Help");
            jmb.add(helpMenu);
            helpMenu.add(HelpMe = new JMenuItem("Help"));
            helpMenu.add(About = new JMenuItem("About"));        
     
     
     
     
     
            GridLayout topPanel = new GridLayout(4,1);
            prog.setLayout(topPanel);  
     
            JPanel P1 = new JPanel();                
            P1.add(targetLabel, FlowLayout.LEFT); 
            prog.add(P1);  
     
            P1.add(textField, FlowLayout.CENTER);    
            prog.add(P1);       
            textField.setPreferredSize(new Dimension(200,30));
     
            P1.add(browseButton, FlowLayout.RIGHT);  
            prog.add(P1);       
     
     
     
     
            JPanel P2 = new JPanel();                    
            P2.add(sourceLabel, FlowLayout.LEFT);    
            prog.add(P2);    
     
            P2.add(textField1, FlowLayout.CENTER);
            textField1.setPreferredSize(new Dimension(200,30));
            prog.add(P2);
     
            P2.add(browseButton1, FlowLayout.RIGHT);
            prog.add(P2);
     
            JPanel P3 = new JPanel();
            P3.add(fc, FlowLayout.LEFT);               
    ;
            prog.add(P3);
     
     
     
            JPanel P4 = new JPanel();
            P4.add(copyButton, FlowLayout.LEFT);
            prog.add(P4);
     
     
     
     
     
            Exit.addActionListener(new ActionListener(){
               public void actionPerformed (ActionEvent e){
                   exitMethod();
               }
            });
     
             oneWaySynch.addActionListener(new ActionListener(){
               public void actionPerformed (ActionEvent e){
                   oneWayMethod();
               }
            });       
     
            twoWaySynch.addActionListener(new ActionListener(){
               public void actionPerformed (ActionEvent e){
                   twoWayMethod();
               }
            });
     
             HelpMe.addActionListener(new ActionListener(){
                public void actionPerformed (ActionEvent e){
                   helpMethod(); 
                }
                });
     
             About.addActionListener(new ActionListener(){
                public void actionPerformed (ActionEvent e){
                   aboutMethod();             
                }
                });           
     
             browseButton.addActionListener(new ActionListener(){
                public void actionPerformed (ActionEvent e){
                   browseButtonMethod();             
                }
                }); 
     
             browseButton1.addActionListener(new ActionListener(){
                public void actionPerformed (ActionEvent e){
                   browseButton1Method();             
                }
                }); 
     
     
             copyButton.addActionListener(new ActionListener(){
                public void actionPerformed (ActionEvent e){
                   copyMethod();             
                }
                });    
     
            prog.setVisible(true); //Display the window to the user!        
     
        } //end of method Synch()
     
            public void exitMethod() {
            if(JOptionPane.showConfirmDialog(null,"Are you sure you want it to close?", "Confirm Exit", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
                System.exit(0);    
            }
     
     
            public void oneWayMethod() {
            JOptionPane.showMessageDialog(null, "One way sync has been activated.");
     
     
            }
            public void twoWayMethod() {
            JOptionPane.showMessageDialog(null, "Two way sync has been activated.");
     
            } 
     
            public void aboutMethod() {
            JOptionPane.showMessageDialog(null, "This is a file synchronization program, to speed things up, and over all make it easier for you.");
                   }
     
            public void helpMethod() {
            JOptionPane.showMessageDialog(null, "If you are needing assistance please contact me via email: egamespaypal@gmail.com or by phone 1-901-619-9413.");
     
     
            }
     
            public void browseButtonMethod() {
            JOptionPane.showMessageDialog(null, "The browse button has been clicked!");
     
     
            }
     
     
            public void browseButton1Method() {
            JOptionPane.showMessageDialog(null, "The browse button has been clicked!");
     
     
            }
     
            public void copyMethod() {
            JOptionPane.showMessageDialog(null, "Copying has commenced, watch the magic happen!");
     
     
            } 
     
    }


    my main

    package synch;
     
     
    import javax.swing.JFrame;
    import java.awt.*;
     
    public class Main {
     
     
     
     
    public static void main(String[] args) {        
     
            try{
     
                Synch myProg = new Synch();
     
     
            }
     
            catch(Exception Ex){
     
     
        }
     
     
     
        }
     
    }


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Some much needed help, and questions.

     JFrame prog = new JFrame("Chris's file synchronization");
     
            GridLayout topPanel = new GridLayout(4,1);
            prog.setLayout(topPanel);  
     
            JPanel P1 = new JPanel();                
            P1.add(targetLabel, FlowLayout.LEFT); 
            prog.add(P1);  
     
            P1.add(textField, FlowLayout.CENTER);    
            prog.add(P1);       
            textField.setPreferredSize(new Dimension(200,30));
     
            P1.add(browseButton, FlowLayout.RIGHT);  
            prog.add(P1);       
     
            JPanel P2 = new JPanel();                    
            P2.add(sourceLabel, FlowLayout.LEFT);    
            prog.add(P2);    
     
            P2.add(textField1, FlowLayout.CENTER);
            textField1.setPreferredSize(new Dimension(200,30));
            prog.add(P2);
     
            P2.add(browseButton1, FlowLayout.RIGHT);
            prog.add(P2);

    in the code above you are adding Panel p1 and Panel p2 two times in the frame , which is not possible , one object cannot be available at two places .

    So add components into the panel you want to add and then one time add that panel into frame.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. JTextPane questions.
    By sunde in forum AWT / Java Swing
    Replies: 1
    Last Post: March 28th, 2011, 04:18 PM
  2. Many questions
    By SharpT in forum What's Wrong With My Code?
    Replies: 11
    Last Post: January 18th, 2011, 09:56 PM
  3. A few questions
    By adenverd in forum Java Theory & Questions
    Replies: 3
    Last Post: May 26th, 2010, 04:34 AM
  4. [SOLVED] Some serious questions,
    By Time in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 17th, 2010, 03:52 AM
  5. Java Questions! :)
    By xs4rdx in forum Java Theory & Questions
    Replies: 0
    Last Post: February 21st, 2010, 08:40 AM