Results 1 to 13 of 13
  1. #1
    plrca2 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default Groups of swing objects

    I've got a group of swing objects that I'd like to add to my interface. I've created an Object called Entry that contains all the elements. I can add each of the elements on their own, but when I try to add them all together through the Entry object, all I get is a blank space. I've looked at custom swing objects, but it seems a bit complicated for my situation. Thanks for any help!

    -Paul

  2. #2
    plrca2 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    I don't have the code with me. For now I can tell you that the code for the elements was generated by netbeans and copied into the Entry object. It was something along the lines of this:

    Java Code:
    class Entry
    public Entry(){
      public JButton button = new JButton("Hello");
      public JButton button2 = new JButton("Hello2");
    }
    
    class UI
    {
    public static void main(String[] args){
    //code to make the frame here
      JPanel panel = new JPanel();
      Entry entry = new Entry();
      panel.add(entry);
    }
    This isn't exact, but it does show what I've been trying to do (I hope). The goal is to get all the ui elements in Entry to show in the UI

    Thanks
    -Paul
    Last edited by plrca2; 12-06-2010 at 04:40 PM. Reason: Added code tags

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by plrca2 View Post
    I've got a group of swing objects that I'd like to add to my interface. I've created an Object called Entry that contains all the elements. I can add each of the elements on their own, but when I try to add them all together through the Entry object, all I get is a blank space. I've looked at custom swing objects, but it seems a bit complicated for my situation.
    I'm not sure how we can help you given the information presented. I assume that you've created a GUI with NetBeans, and that in of itself may present some problems in our ability to help you, since it will be hard for you to create a small program that demonstrates your problem. I suggest you look into hand-coding your Swing app. For more specific advice, we'll likely need to see code, hopefully small, hopefully compilable -- an SSCCE as suggested above.

    And welcome to the forum!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by plrca2 View Post
    I don't have the code with me. For now I can tell you that the code for the elements was generated by netbeans and copied into the Entry object. It was something along the lines of this:

    Java Code:
    class Entry
    public Entry(){
      public JButton button = new JButton("Hello");
      public JButton button2 = new JButton("Hello2");
    }
    
    class UI
    {
    public static void main(String[] args){
    //code to make the frame here
      JPanel panel = new JPanel();
      Entry entry = new Entry();
      panel.add(entry);
    }
    This isn't exact, but it does show what I've been trying to do (I hope). The goal is to get all the ui elements in Entry to show in the UI

    Thanks
    -Paul
    Thanks for posting more information, but for me at least, it's not enough. One key though when adding a component to a container (often another component) is the layout managers that you use. Have you gone through the Swing layout manager tutorial yet? If not, I strongly suggest that you do.

    Luck.

  5. #5
    plrca2 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Thanks for posting more information, but for me at least, it's not enough. One key though when adding a component to a container (often another component) is the layout managers that you use. Have you gone through the Swing layout manager tutorial yet? If not, I strongly suggest that you do.

    Luck.
    Thanks for the welcome, fubarable!

    I'm using the boxlayout manager. I've been able to add elements one by one; that's no problem. It's when I put them in in my Entry object that things don't work. If need be, I can get the code this evening.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by plrca2 View Post
    I'm using the boxlayout manager. I've been able to add elements one by one; that's no problem. It's when I put them in in my Entry object that things don't work. If need be, I can get the code this evening.
    There are so many ways for things not to work, that yeah, I think we'll need to see code.

  7. #7
    plrca2 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    That's odd. Alberstare had just said something that I think might be on the right track, but now his reply is gone.

    Is it possible to make Entry extend JPanel and then add it to my UI?
    Currently, it extends JComponent.

    We'll see.

    Thanks again,
    -Paul

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  9. #9
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    Wow my first somewhat serious post and I get banned. Like i said b4 extend jpanel create a jframe in main and add panel to frame. Also make sure u add components to the panel

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Quote Originally Posted by Bertstar View Post
    Wow my first somewhat serious post and I get banned. Like i said b4 extend jpanel create a jframe in main and add panel to frame. Also make sure u add components to the panel
    1. Why extend JPanel? (not jpanel)
    2. If you can't be bothered to use uppercase letters where appropriate and spell words like 'before' 'you' in full, why exert yourself to respond at all?

    db

  11. #11
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    1. Why extend JPanel? (not jpanel)
    2. If you can't be bothered to use uppercase letters where appropriate and spell words like 'before' 'you' in full, why exert yourself to respond at all?

    db
    Wow, ur nice. I am on my phone and if he doesn't know it's JPanel instead of jpanel then he has bigger problems. Extending jpanel (yes I didn't upercase so u mad) implies that entry is a jpanel that he can add the buttons. Use your is a and has a relationships plz.

  12. #12
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    LOL did u delete my gif, but not my accidental double post? It wasnt even an inappropriate gif. its not my fault daryl got mad when i stopped trolling and actually helped someone.

    db

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bertstar View Post
    LOL did u delete my gif, but not my accidental double post? It wasnt even an inappropriate gif. its not my fault daryl got mad when i stopped trolling and actually helped someone.

    db
    When you want to help, you can be quite helpful. I beg of you to keep this up and leave the rest alone.

Similar Threads

  1. how to sort jtable with row groups
    By mordjah in forum AWT / Swing
    Replies: 0
    Last Post: 10-25-2010, 05:23 PM
  2. Replies: 9
    Last Post: 06-26-2010, 03:16 PM
  3. Showing/Hiding groups with "triangle flippities"
    By Kendall in forum AWT / Swing
    Replies: 2
    Last Post: 03-30-2010, 05:07 PM
  4. Get all groups from a regular expression match?
    By johann_p in forum New To Java
    Replies: 0
    Last Post: 05-16-2008, 07:50 PM
  5. Capturing Groups using regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:19 AM

Tags for this Thread

Posting Permissions

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