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

Thread: Attempting something complicated with netbeans (involving GUI), looking for advice

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Attempting something complicated with netbeans (involving GUI), looking for advice

    I'm not experienced with building normal software, just programming assignments in an academic setting, but a few days ago I decided to attempt an independent project separate from school: a gift organizer. The idea is that a user could build a file for each person they wanted to give a gift to, then add fields for notes like clues they have about each person to help them figure out a really good gift.

    I've used Java Webstart before, but my experience with Netbeans and GUI building is very limited and I don't know how to save the data for the application to anything but a text file. Of course if a text file is an okay format to save this stuff, then I guess I really only need to learn more about building GUIs. Netbeans has a tool to help build a GUI so I figured I would start with this forum.

    P.S.: It might take me some time between my schedule and inexperience to finish the project, but when I do, I intend to make it available for free via my website or a code repository (ex. SourceForge or GitHub).


  2. #2

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    thanks for sharing your idea. Have you got started? Did you face any problems?

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    I've figured out what I want to do, and I have the basic idea of how to implement it. I've used netbeans GUI editor before. I guess the main problem I'm encountering is also the main obstacle to building this, I need to be able to create Objects of Type Profile that will be created and rendered as tabs on click of the right GUI element and then to automatically save, such that if immediately after clicking I quit the application and later relaunched it, that tab would be open and aligned with all the other tabs opened before it. It might be the hardest part to program, its difficult to breakup into substeps, and that's the main thing that's keeping me from progressing at this point.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    The key to this and any programming exercise, and what you must do now, is to break your project into small steps and start working on each small step, one at a time. Please feel free to come on back if you stuck on one of these steps, and if you show us your code and ask specific questions, we'll be better able to help you.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    Edit: Ok, sounds good, when I have a specific question, I'll posit here.

    My code at this point is pretty basic, my next goal is to be able to launch it and add fields, then save the fields, and that's pretty much all the first version has to do. Here are some screenshots I uploaded to my webpage so you can get an idea of what I'm trying to get it to look like when done: Link to Screenshots Page

    Like I've said, I've been using the Netbeans IDE (its mostly the code the gui editor generated), and here is my code so far:
    giftorganizer.Configuration:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package giftorganizer;
     
    import GUI.MainWindow;
     
    public class Configuration {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            MainWindow mw = new MainWindow();
        }
    }
    GUI.Profiler:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package GUI;
     
    public class Profiler extends javax.swing.JPanel {
     
        /**
         * Creates new form Profiler
         */
     
        public Profiler() {
            initComponents();
        }
     
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jTextField1 = new javax.swing.JTextField();
            label1 = new java.awt.Label();
            jLabel1 = new javax.swing.JLabel();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jLabel3 = new javax.swing.JLabel();
            jSeparator1 = new javax.swing.JSeparator();
            label2 = new java.awt.Label();
            jButton2 = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jScrollPane2 = new javax.swing.JScrollPane();
            jTextArea2 = new javax.swing.JTextArea();
     
            jTextField1.setText("John Doe");
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
     
            label1.setText("Name:");
     
            jLabel1.setText("Gift Ideas: ");
     
            jTextField2.setText("jTextField2");
     
            jTextField3.setText("jTextField3");
     
            jLabel2.setText("Title/ Descr.");
     
            jButton1.setText("Add Another Gift to List");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jLabel3.setText("Link");
     
            label2.setText("Clues:");
     
            jButton2.setLabel("Add Another Clue Space");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jTextArea1.setText("mentions he always wanted to own a toy store");
            jScrollPane1.setViewportView(jTextArea1);
     
            jTextArea2.setColumns(20);
            jTextArea2.setRows(5);
            jScrollPane2.setViewportView(jTextArea2);
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jLabel1)
                                .add(jLabel2)
                                .add(jLabel3))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(layout.createSequentialGroup()
                                    .add(0, 304, Short.MAX_VALUE)
                                    .add(jButton1))
                                .add(jTextField2)
                                .add(jTextField3)))
                        .add(layout.createSequentialGroup()
                            .add(label1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(0, 0, Short.MAX_VALUE))
                        .add(layout.createSequentialGroup()
                            .add(label2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButton2))
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                            .add(0, 0, Short.MAX_VALUE)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
                                .add(jScrollPane2))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(label1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(14, 14, 14)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel1)
                        .add(jButton1))
                    .add(5, 5, 5)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel2))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel3))
                    .add(18, 18, 18)
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(label2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jButton2))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(18, 18, 18)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(90, Short.MAX_VALUE))
            );
        }// </editor-fold>
     
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JSeparator jSeparator1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextArea jTextArea2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        private java.awt.Label label1;
        private java.awt.Label label2;
        // End of variables declaration
    }
    GUI.MainWindow:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package GUI;
     
    public class MainWindow extends javax.swing.JFrame {
     
        /**
         * Creates new form MainWindow
         */
        public MainWindow() {
            initComponents();
        }
     
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jButton1 = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jButton1.setText("Add New Profile Tab");
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(jTabbedPane1)
                    .addContainerGap())
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(0, 653, Short.MAX_VALUE)
                    .add(jButton1)
                    .add(17, 17, 17))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jButton1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 33, Short.MAX_VALUE)
                    .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 502, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /*
             * Set the Nimbus look and feel
             */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /*
             * If Nimbus (introduced in Java SE 6) is not available, stay with the
             * default look and feel. For details see
             * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /*
             * Create and display the form
             */
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
                    new MainWindow().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JTabbedPane jTabbedPane1;
        // End of variables declaration
    }

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    Update, so at the moment, I'm trying to get a simple interaction working. When someone clicks the add button, when someone clicks the add new profile tab button, a tab should appear in the tab pane. So I'm trying to achieve this within the netbeans GUI editor.

    So I guess to break down that task further. How do I create a method that will get the JTabbedPane1 to add a Profiler Panel as a tab?

  7. #7
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Attempting something complicated with netbeans (involving GUI), looking for advice

    Myself I would tend to favor using a CardLayout to swap views, but the concept on how to perform these actions -- swap views or add a JTabbedPane are similar. At its most basic, you could have the control or "handler" code, the code that responds to the button press, have references to the GUI components that you'd like changing. In your case the ActionListener would have a reference to the JTabbedPane and would tell it to accept a new tab with your Profiler Panel as the tab. The details will all depend on the current code.

    Other issues:
    • Since you're doing this project as a learning exercise, and since you're fairly new to Swing, I suggest that you avoid using generated code such as code created by the NetBeans' drag and drop GUI builder. There are several reasons for this recommendation including the fact that it can be extremely frustrating to use this tool if you're not very familiar with the Swing library since it can be difficult to create more than the most basic components with it, and also since using this tool can shield you from having to learn the internals of Swing which is a disservice. I suggest that instead you code this "by hand", but that sure, use a code generator if desired once you're much more comfortable with the Swing library.
    • Even if you use a code generator, make sure that you change the name of the variables created from their default names to names that better reflect what the variables do in order to make your code more self-commenting. Then if you run into problems, this will make it *much* easier for ourselves and for your future self to understand just what your intentions are with your code.
    • Consider Googling and studying an article or two on the MVC or Model-View-Control design pattern as it can be a very useful paradigm with which to structure your GUI, and would make it much easier to debug, adapt and enhance your project.


    Much luck!

Similar Threads

  1. Netbeans GUI help
    By kprofgold in forum AWT / Java Swing
    Replies: 1
    Last Post: February 26th, 2012, 08:02 AM
  2. Am I doing it rite? Using netbeans GUI builder
    By erm3r in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2011, 10:48 AM
  3. NetBeans-style GUI
    By susieferrari in forum Java Theory & Questions
    Replies: 7
    Last Post: March 31st, 2011, 09:40 AM
  4. Modifying a complicated object with dialog boxes
    By hunter555 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 27th, 2011, 03:02 PM
  5. Need some help/advice for my GUI code.
    By J-Ark in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 4th, 2010, 12:23 PM