g00se's Profile User Rating: *****

Reputation: 2687 Guru
Group:
Mentors
Active Posts:
11,348 (5.23 per day)
Joined:
20-September 08
Profile Views:
32,124
Last Active:
User is offline Today, 04:12 PM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Linux
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
Java

Latest Visitors

Icon   g00se has not set their status

Posts I've Made

  1. In Topic: Why is Java so circuitous and tortuous compared to C/C++?

    Posted 29 Aug 2014

    Quote

    for embedded solutions C++ is short and to the point.

    To oversimplify, the chief benefit of C++ over C is that it adds object orientation. That's seldom apt in embedded contexts, so C/Assembler will normally be used there
  2. In Topic: Is this the proper way to add to a generic list?

    Posted 28 Aug 2014

    Yes, though it should be
    ListOfGeneric<Person> x = new ListOfGeneric<Person>();
    


    Also it must be said that your code as it stands does not add anything to the functionality of LinkedList
  3. In Topic: Fix Dimensions of JPanel

    Posted 28 Aug 2014

    Quote

    However, GridBagLayout is the right layout manager if you want a form look


    Yes, although today a BoxLayout or a SpringLayout could be used. Having said that, the code i referred to earlier uses a GridBagLayout:

    package net.proteanit.gui;
    
    import java.awt.GridBagConstraints;
    import static java.awt.GridBagConstraints.EAST;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.text.JTextComponent;
    
    
    public class FormMaker extends JPanel {
        private int rowCount;
        private Map<String, JComponent> fields;
        private Insets spacer;
    
        /**
         *
         */
        public FormMaker() {
            super();
            setLayout(new GridBagLayout());
            fields = new HashMap<String, JComponent>();
            spacer = new Insets(0, 10, 0, 0);
        }
    
        public FormMaker(String... fields) {
            this();
    
            for (String field : fields) {
                this.addField(field);
            }
        }
    
        public void addField(String label, String key) {
            if (fields.containsKey(key)) {
                throw new IllegalArgumentException(String.format(
                        "Key '%s' already used. Choose another value or use addField(String label, String key).",
                        key));
            }
    
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = rowCount;
            gbc.anchor = GridBagConstraints.WEST;
            gbc.weightx = 0;
    
            JLabel l = new JLabel(label);
            add(l, gbc);
    
            gbc.gridx = 1;
            gbc.weightx = 1.0;
            gbc.insets = spacer;
            gbc.fill = GridBagConstraints.HORIZONTAL;
    
            JTextField tf = new JTextField();
            add(tf, gbc);
    
            rowCount++;
            fields.put(key, tf);
        }
    
        /**
         * @param name
         *            The field label and key for the JTextField
         */
        public void addField(String name) {
            addField(name, name);
        }
    
        public void addFields(String fields) {
            for (String s : fields.split("\\s*,\\s*")) {
                addField(s);
            }
        }
    
        public JComponent getField(String name) {
            return fields.get(name);
        }
    
        public String getText(String name) {
            return ((JTextComponent) fields.get(name)).getText();
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
        }
    }
    
    


    With your fields:

    package net.proteanit.gui;
    
    import java.awt.Container;
    
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    
    public class F extends JFrame {
        private void setGui() {
            try {
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
                Container cp = getContentPane();
                FormMaker fp = new FormMaker();
                final String[] expenses = {
                        "Phone Bill", "Car Insurance", "Rent", "Utilities", "Gas",
                        "Groceries", "Recreation",
                    };
    
                for (int i = 0; i < expenses.length; i++) {
                    fp.addField(expenses[i]);
                }
    
                cp.add(fp);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                        public void run() {
                            F f = new F();
                            f.setGui();
                            f.setSize(200, 200);
                            f.setVisible(true);
                        }
                    });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    
  4. In Topic: Fix Dimensions of JPanel

    Posted 28 Aug 2014

    I must say i found the fact that it was so difficult to make a form in Swing surprising. Admittedly it was before the more advanced layouts came along, but it led me to write my own FormMaker class. I'll post the code later
  5. In Topic: Exception in thread "AWT-EventQueue-0" java.lang.Unsupported..

    Posted 28 Aug 2014

    So, make the button handler call the other ctor that IS implemented. I'm not going to write the code for you i'm afraid

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private
Website URL:
Website URL  http://technojeeves.com

Comments

  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    reznum Icon

    19 Jul 2014 - 07:21
    Amazing guy
    Really appreciate your help :)
  2. Photo

    Nageshvk Icon

    28 Feb 2014 - 07:57
    can any body tell in Java SWINGS when do RepaintManager.scheduleProcessingRunnable() method is called? I am getting NPE while running the applet in JRE 1.7.51
  3. Photo

    john111 Icon

    27 Feb 2014 - 09:57
    any chance you can help me pleasee:
    http://www.dreamincode.net/forums/topic/341051-java-applet-creating-bar-chart-from-user-input/
  4. Photo

    trixt.er Icon

    30 Dec 2013 - 10:13
    *avatar image
  5. Photo

    trixt.er Icon

    30 Dec 2013 - 10:13
    Hey g00se why doesn't your avatar show up in your profile, but it does in your posts?
  6. Photo

    trixt.er Icon

    30 Dec 2013 - 08:12
    g00se be my friend! :)
  7. Photo

    nishakantsharma Icon

    07 Oct 2013 - 01:28
    how to remokve space between div tags
  8. Photo

    Anitush Icon

    21 Aug 2013 - 06:37
    hey could you help on my topic External Methods or error in code under Java pretty please. Thanks
  9. Photo

    Abomosa Icon

    20 Apr 2013 - 15:33
    can you help me more in my program
    http://www.dreamincode.net/forums/topic/319095-calculate-average-using-method/
  10. Photo

    Abomosa Icon

    20 Apr 2013 - 15:25
    http://www.dreamincode.net/forums/topic/319095-calculate-average-using-method/page__gopid__1839513&#entry1839513
  11. Photo

    raghav.naganathan Icon

    09 Dec 2012 - 09:41
    Congrats on the 1800 :)
  12. Photo

    raghav.naganathan Icon

    21 Nov 2012 - 04:48
    Dude, your rep just crossed the Hardy Ramanujan number(1729) :) Cheers :)
  13. Photo

    JeffBurnsRed Icon

    14 Nov 2012 - 07:10
    Thanks for all of your help
  14. Photo

    TheCodeNoob Icon

    28 Sep 2012 - 03:49
    You are useless and you should feel useless.
  15. Photo

    GameDesigner34 Icon

    31 Aug 2012 - 18:58
    Thank you so much for your help. I finished my program and you were the best at helping me.
  • (2 Pages)
  • +
  • 1
  • 2