Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Question [SOLVED] swing dialogbox size

    I'm using netbeans. I'm making a swing application, and I have 1 thing I need help with and a suggestion about something else.
    1. In my main JFrame, I have a menu bar with File Edit and Help menus. I have a Menu Item that says "About..." in the Help menu. I have a dialogbox that I am going to put version, information etc. in. In the dialog box Code properties, in After-All-Set Code, I had put aboutdialog.setVisible(false);, but when I take it away and run program it isn't there anyway so I think since it's an "other component", its default state is hidden. So then in the about menu item's action performed event, I put aboutdialog.setVisible(true);, when I run the program, when I click the about menu item, the dialog is always in the top-left corner and is very small, only like 10 height 20 width probably. I have tried changing all the properties that have to do with this and it doesnt work. How can I get the DialogBox to start out same spot as the main JFrame and have it's size be the same that I set in the Design view? Please and Thankyou tell me what's wrong.
    2. Not as urgent, I have other components of the project, JFrame's also. I have buttons on the main app that I will link to them, but how will I do this? How can I make them come up? or can I call their main method? And then would i make the Main app get closed and that new one appear? Or can I make them all kind of go onto the same area... thanks in advance.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

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

    Default

    Part of your question may be more NetBeans-specific than Java-specific. I may be able to help you with the latter but not the former. If you don't get prompt help for your NetBeans-related question, you may wish to ask it on a NetBeans site, but I do ask that out of consideration for all here who may help you or have the same question, please post links in all cross-posts to all cross-posts.

    Anyway, as to number 1: I set the location of my JDialogs with either setLocation(...) or setLocationRelativeTo(...). If I want it centered on the screen, I'll call setLocationRelativeTo(null) after packing the dialog. What I don't know is how to do this in a nice way with NetBean's Matisse Swing code generation.

    The usual way in Swing is to call setPreferredSize(new Dimension(...)) on the dialog as most layout managers will attempt to use the preferred size of components when laying them out. The components are layed out when pack() is called on the root pane. Again, I'm not sure how this is done with NetBean's Matisse Swing code generation software.

    Problem 2: I'm not 100% clear on what you are trying to do here and what you've done already. If you could go into greater detail here, you'll likely get better help from me and others. If you are talking about having components that show or don't show depending on the state of your application, you may want to explore using a CardLayout. This allows you to swap components as if they were cards on the top of a deck and often is used to swap JPanels that hold different levels of a program.

    I'm not sure what you mean by main method. You know of course that while any of the classes that make up your program can have a main method, only one can called to start up your program.

    Much luck,

    Pete

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    I'm not concerened about the location as much, but the preffered size is much larger then how big it is when i run it. I don't need generated code to call the methods you talked about, I can manually code them. Instead of going on netbeans websote, should I just post in java-forms.org Netbeans IDE subforum? For #2, I have a "Main Menu" JFrame class. Then I have other JFrame classes that I want to go to. That layered thing sounds okay, but wouldn't they all have to be in the same class? Or should I have 1 big JFrame GUI class and it calls methods from the other classes? If the stacked panels thing needs to be in one class, that would work I guess, but would make a really big class to have all the GUI in 1 class, since the JFrame I already made which I want to be able to access through the main menu is mainly just 1-3 line each event methods.. But I like the stacked panels idea.. For the main method I ment could I make another class that has a main method run by clicking a button in the main menu. But another component I made for the Application is not GUI but could be in the main GUI class and only use a few gui controls and event methods to run.. I hope this isn't too confusing.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

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

    Default

    I don't need generated code to call the methods you talked about, I can manually code them.
    It's not the methods I'm talking about, it's the code-generated JFrames and dialogs and what-nots.

    Instead of going on netbeans websote, should I just post in java-forms.org Netbeans IDE subforum?
    Yep, that would be fine, but again, out of consideration for all, please leave links from that thread to this one and visa-versa.

    For #2, I have a "Main Menu" JFrame class. Then I have other JFrame classes that I want to go to. That layered thing sounds okay, but wouldn't they all have to be in the same class?
    Good God no. I usually code to the JPanel, not to the JFrame, and my panels are often each in their own class. Just because we're working with GUIs doesn't mean that we should forgo good coding practices including dividing distinct ideas into separate classes.

    Or should I have 1 big JFrame GUI class and it calls methods from the other classes?
    Again, you should be thinking of JPanels, not JFrames.

    If the stacked panels thing needs to be in one class, that would work I guess, but would make a really big class to have all the GUI in 1 class, since the JFrame I already made which I want to be able to access through the main menu is mainly just 1-3 line each event methods.. But I like the stacked panels idea.. For the main method I ment could I make another class that has a main method run by clicking a button in the main menu. But another component I made for the Application is not GUI but could be in the main GUI class and only use a few gui controls and event methods to run.. I hope this isn't too confusing.
    Most of your questions sound as if you haven't yet gone through the Sun Swing tutorial, and this is what I recommend that you do as soon as you can, especially the sections on how to create and work with Swing widgets without using NetBeans-generated code. You can still use NetBeans, but the techniques and skills that you'll learn from the tutorials will help you break out of the box that you and NetBeans have stuffed you in. It really is mind-blowing the power of Swing, and with this knowledge, you will open up your options immensely. Good luck.

  5. #5
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    don't you use setSize(,) for JDialog in your code?

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    setLocation() or getLocation() ?

  7. #7
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Yeah I know i have set all the properties that have to do with size, manually and in the design editor still doesnt work. Fubarable, That's exactly what I would want then To have each as it's own JPane which would all be layered.. But Panels aren't top level containers, dont you need one for a GUI? Or do I use another Class that holds all the other classes' panels?
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  8. #8
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    you can fix your JDialog location to your JFrame location. It is quite possible thing to do I guess )
    If your JFrame isn't in the center of the screen and JDialog as well you can use code like a:
    Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width-frame.getSize().width)/2,(d.height-frame.getSize().height)/2);
    It provides your JFrame appear always in the center of any screen. Maybe that will help? Report

  9. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    And then would i make the Main app get closed and that new one appear?
    o' course you can. You have to implement window listener as windowClosing() you know I mean?
    Then if your JFrame is closing you can get the event and execute some code as maybe even opening another JFrame.

  10. #10
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Fubarable: I'm going through the java sun swing tutorials like you suggested. I am now organizing the project as follows: TopPackage(my project name).JFrame form class. That contains the JFrame and a tool bar, and will have some dialogue boxes i.e. the About dialogue box. Then In the top package I have a subpackage of it called gui, so Toppackage.gui . It has all the JPanels Including MainMenu, and places you can get too from the main menu, all JPanel forms. Then I have another subpackage of the top one, called components(so Toppackage.components). I might rename it since it doesn't describe well, but it contains the classes that the JPanels use, If they need one. But I don't know yet how to put the whole sandwhich of swing containers together, or make the layers change. I expect I will find out in reading the tutorials. Is the way I organized my stuff OK? Oh, and my Panels will all have to be the same size or it would be kind of weird, right? Let me know what you think about all this. (the top package isnt actually called that incase you thought that)
    Last edited by MK12; 02-08-2009 at 10:49 PM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

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

    Default

    It sounds like you're making wonderful progress. If you end up swapping JPanels with a CardLayout, all of the swapped panels will be displayed the same size as it's one of the properties of the CardLayout.

    Tying non-GUI code to GUI code, and tying one GUI component to another can get tricky, so some thought will be required to do it will. You want to strive for as loose coupling as possible. I would work on small bits at a time, and if you get stuck come on back.

    I have a small sample program that uses CardLayout lying about somewhere. If I can find it, I'll post it here.

    Pete

  12. #12
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Well, there are a lot of lauout managers it is sometimes depends of your IDE. Actually, the libs you have response for this...
    SO, as i got you think to use a tamplate and just want to make some modifocations, right?
    If you really can writing java codes it shan't take over tham 15 minutes.
    Write more brief plz. Describe the think you want in the result (

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

    Default

    For example, here are 3 classes that produce (note that they don't extend) JPanels:

    CardIntro.java -- shows initial jlabel. First panel seen
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Font;
    
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    
    /**
     * Shows introductory JLabel
     * @author Pete
     */
    public class CardIntro
    {
      private static final int FONT_SIZE = 46;
      private JPanel mainPanel = new JPanel();
    
      public CardIntro(String text)
      {
        JLabel label = new JLabel(text, SwingConstants.CENTER);
        label.setFont(label.getFont().deriveFont(Font.BOLD, FONT_SIZE));
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(label);
      }
    
      public JComponent getComponent()
      {
        return mainPanel;
      }
    
    }
    CardWorkPanel.java -- Allows selection of colors for image panel to display
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.Font;
    
    import javax.swing.BorderFactory;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    
    /**
     * Allows selection of colors for image panel to display
     * @author Pete
     */
    public class CardWorkPanel
    {
      // this jpanel is returned from the getComponent() method
      private JPanel mainPanel = new JPanel();
      
      private JComboBox colorCombo1 = new JComboBox(Colors.values());
      private JComboBox colorCombo2 = new JComboBox(Colors.values());
    
      public CardWorkPanel()
      {
        int ebgap = 5;
        mainPanel.setBorder(BorderFactory.createEmptyBorder(
            ebgap, ebgap, ebgap, ebgap));
        
        JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 0));
        comboPanel.add(colorCombo1);
        comboPanel.add(colorCombo2);
    
        colorCombo1.setSelectedItem(Colors.RED);
        colorCombo2.setSelectedItem(Colors.BLUE);
        
        JLabel titleLabel = new JLabel("Select Colors to Display:", 
            SwingConstants.CENTER);
        titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 16));
        
        int blGap = 20;
        mainPanel.setLayout(new BorderLayout(blGap, blGap));
        mainPanel.add(titleLabel, BorderLayout.NORTH);
        mainPanel.add(comboPanel, BorderLayout.CENTER);
      }
    
      public Color getColor1()
      {
        return ((Colors) colorCombo1.getSelectedItem()).getColor();
      }
    
      public Color getColor2()
      {
        return ((Colors) colorCombo2.getSelectedItem()).getColor();
      }
    
      public JComponent getComponent()
      {
        return mainPanel;
      }
    
      enum Colors
      {
        BLACK("Black", Color.black), 
        RED("Red", Color.red), 
        ORANGE("Orange", Color.orange), 
        YELLOW("Yellow", Color.yellow), 
        GREEN("Green", Color.green), 
        BLUE("Blue", Color.blue), 
        MAGENTA("Magenta", Color.magenta);
    
        private String name = "";
        private Color color = Color.black;
    
        private Colors(String name, Color color)
        {
          this.name = name;
          this.color = color;
        }
    
        public Color getColor()
        {
          return color;
        }
    
        public String toString()
        {
          return name;
        }
      }
    }
    CardImagePanel.java -- Uses Colors selected to draw simple image
    Java Code:
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Rectangle2D;
    
    import javax.swing.JPanel;
    import javax.swing.JComponent;
    
    /**
     * Uses Colors selected to draw simple image
     * @author Pete
     */
    public class CardImagePanel
    {
      private static final Dimension IMAGE_PANEL_SIZE = new Dimension(300, 200);
      private Color color1;// = Color.blue;
      private Color color2;// = color1.red;
      private JPanel mainPanel = new JPanel()
      {
        protected void paintComponent(Graphics g)
        {
          super.paintComponent(g);
    
          Graphics2D g2 = (Graphics2D) g;
          // g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
          // RenderingHints.VALUE_ANTIALIAS_ON);
          Dimension d = mainPanel.getSize();
          int gap = 10;
          Rectangle2D rect = new Rectangle2D.Double(gap, gap, 
              d.width - 2*gap, d.height - 2*gap);
          g2.setColor(Color.darkGray);
          g2.setStroke(new BasicStroke(5));
          g2.draw(rect);
          if (color1 != null && color2 != null)
          {
            g2.setPaint(new GradientPaint(0, 0, color1, 50, 50, color2, true));
            g2.fill(rect);
          }
        }
      };
    
      public CardImagePanel()
      {
        mainPanel.setPreferredSize(IMAGE_PANEL_SIZE);
      }
    
      public void setColor1(Color c1)
      {
        color1 = c1;
        mainPanel.repaint();
      }
    
      public void setColor2(Color c2)
      {
        color2 = c2;
        mainPanel.repaint();
      }
    
      public JComponent getComponent()
      {
        return mainPanel;
      }
    }
    And this class produces a JPanel which holds another JPanel that swaps the "cards" above
    CardMainPanel.java
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    
    /**
     * Has cardHolderPanel, the panel that uses the
     * CardLayout to allow swapping of the "Card"
     * Panels
     * @author Pete
     *
     */
    public class CardMainPanel
    {
      private static final String WORK_PANEL = "Work Panel";
      private static final String IMAGE_PANEL = "Image Panel";
      private JPanel mainPanel = new JPanel();
      private CardLayout cardlayout = new CardLayout();
      private JPanel cardHolderPanel = new JPanel(cardlayout);
      private CardWorkPanel cardWorkPanel = new CardWorkPanel();
      private CardImagePanel cardImagePanel = new CardImagePanel();
    
      public CardMainPanel()
      {
        JButton swapPanelBtn = new JButton(WORK_PANEL);
        swapPanelBtn.addActionListener(new SwapBtnListener());
        JPanel btnPanel = new JPanel();
        btnPanel.add(swapPanelBtn);
        
        // add the cards to the cardholder
        cardHolderPanel.add(new CardIntro("Welcome").getComponent(), "Intro");
        cardHolderPanel.add(cardWorkPanel.getComponent(), WORK_PANEL);
        cardHolderPanel.add(cardImagePanel.getComponent(), IMAGE_PANEL);
        
        int ebgap = 5;
        mainPanel.setBorder(BorderFactory.createEmptyBorder(ebgap, ebgap, ebgap, ebgap));
        mainPanel.setLayout(new BorderLayout(10, 10));
        mainPanel.add(cardHolderPanel, BorderLayout.CENTER);
        mainPanel.add(btnPanel, BorderLayout.SOUTH);
      }
    
      public JComponent getComponent()
      {
        return mainPanel;
      }
      
      private class SwapBtnListener implements ActionListener
      {
        public void actionPerformed(ActionEvent e)
        {
          String command = e.getActionCommand();
          JButton btn = (JButton)e.getSource();
          if (command.equals(WORK_PANEL))
          {
            cardlayout.show(cardHolderPanel, WORK_PANEL);
            btn.setText(IMAGE_PANEL);
          }
          else if (command.equals(IMAGE_PANEL))
          {
            cardlayout.show(cardHolderPanel, IMAGE_PANEL);
            btn.setText(WORK_PANEL);
            cardImagePanel.setColor1(cardWorkPanel.getColor1());
            cardImagePanel.setColor2(cardWorkPanel.getColor2());
          }
        }
      }
    }
    finally a static class that simply creates a JFrame to hold the JPanel produced by CardMainPanel above
    CardMain.java
    Java Code:
    import javax.swing.JFrame;
    
    public class CardMain
    {
      private static void createAndShowUI()
      {
        JFrame frame = new JFrame("CardHolderPanel");
        frame.getContentPane().add(new CardMainPanel().getComponent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args)
      {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
          public void run()
          {
            createAndShowUI();
          }
        });
      }
    }

  14. #14
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Thanks for the example. I have some questions: How do I set the size of the whole thing? Would I set the preffered size of the JFrame? Your example uses a panel to switch between others. I didn't see anywhere showing where the panels are in the frame because You must be able to see the currently focused panel and CardMainPanel (swaps other panels) at all times. Could I use buttons in each panel to switch between panels? And why don't the JPanel classes extend JPanel? Is this necessary? Oh I just noticed, your description of the JFrame is "finally a static class that simply creates a JFrame to hold the JPanel produced by CardMainPanel above"... I thought it held all panels, only the one at the top of the stack visible at a time, and panel on top swapped with swing controls. Can you explain this? Thanks. I'm still going through tutorials, I'm not using the NetBeans swing forms because then I can't edit the generated text. It does feel better coding manually though.
    EDIT: One more Question, I want to set Look&Feel to native, I know how to do it with UIManager, But what I'm asking is where to put it. If I make the JFrame's L&F native to the running system, will the whole thing have that L&F? Or do I have to set each one's. But I don't know where to put the code that sets L&F if the class doesn't have main method (everything but the frame).
    EDIT: couple more questions: Bit off topic, but netbeans makes the class files in the build directory, then theres like 7 more for some of them that say classname$1, then classname$2, etc. What is that?
    next question, I explained my packages already, packageone, packageone.components (relied apon classes), packageone.gui. Should I keep my JFrame class in the packageone, or with the gui's, so that I don't have to import them, and whatever other reasons there are. But then the packageone would have nothing in it, so would there be a point to it... thanks.
    Last edited by MK12; 02-10-2009 at 02:09 PM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  15. #15
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    EDIT: Another Question, sometimes you've declared your swing controls fields, sometimes locals in the contructor. Which should I use, or When do I use which? And what diffence does it make? The NetBeans generator makes declares them in fields. Oh and I'm writing all my classes manually now.
    Sorry that there are so many questions them but when I can't figure it out I've been editing it on here and the list is pretty big now.
    Last edited by MK12; 02-10-2009 at 02:05 PM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  16. #16
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    But doing TOP - 5 doesnt work because the alignment methods ...
    you can set borders to get the effect )

  17. #17
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Thanks that worked... Anyone looking, all those questions in my previous 2 posts haven't been answered.. except this one.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

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

    Default

    I've been on call a bit, and so have not had time to address your questions. Let me try to get to them tonight or tomorrow.

  19. #19
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Ok, thanks.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

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

    Default

    How do I set the size of the whole thing? Would I set the preffered size of the JFrame?
    I usually set the preferred size for a few key components and let the layout managers decide the best size from there. If I really need to set the size of the app, I think you're better off setting the size of the JPanel that will be added to the JFrame's contentPane and not setting the JFrame itself.

    Your example uses a panel to switch between others. I didn't see anywhere showing where the panels are in the frame because You must be able to see the currently focused panel and CardMainPanel (swaps other panels) at all times.
    I'm not sure what you mean by this comment here.

    Could I use buttons in each panel to switch between panels?
    Absolutely.

    And why don't the JPanel classes extend JPanel? Is this necessary?
    No, it's good habit. Many believe that you should strive to extend your apps by composition and avoid inheritance unless necessary. The only places where there's a good argument for extending a JPanel is where you're changing the innate behavior of the JPanel for instance in my example in the CardImagePanel class as I change the JPanel's paintComponent method. Yet even so, you don't even have to have your class extend this panel (and I don't in my example here but instead create an anonymous inner class that extends the JPanel). For instance if you were creating a class "Car" you wouldn't have it inherit "Engine" but rather have it use an Engine object to help form one component of the Car class. Another reason is that one of the principle concepts of OOPs is encapsulation where you try to hide the details of any object from the other objects that use it. If your class inherits from JPanel, it exposes all of JPanel's behaviors to the objects that use your object, and this lack of control is something that needs to be avoided if possible.

    Another advantage is it reduces method clutter. If you use a full-strength IDE such as Eclipse or NetBeans and you type an object and then a period: "foo." the IDE will dutifully list all of the methods available to the foo object. If foo's class derives from JPanel, you will have a tough time finding the method that you're interested in as you'll have to sift through a gazillion methods, whereas if foo's class derives from Object or from another simpler class, the number of methods available is an order of magnitude less or more, making for more time-fficient coding.

    So many of my classes that produce a JPanel do just that, produce a JPanel (or often a JComponent -- one level of abstraction below JPanel), available via my getComponent() method.

    Oh I just noticed, your description of the JFrame is "finally a static class that simply creates a JFrame to hold the JPanel produced by CardMainPanel above"... I thought it held all panels, only the one at the top of the stack visible at a time, and panel on top swapped with swing controls. Can you explain this?
    I made a mistake here: The class holding JFrame is not "static" but OTOH it only has static methods. Think of what a JFrame holds and displays for most of your programs, and that's one thing -- a contentPane. This is a single Component (most often it's actually a JPanel). That's it. All the other doodads and widgets are either held by this contentPane or by components that are held in this contentPane. Swing apps are kind of like a wedding cake. Everything eventually sits on the JFrame, but the JFrame really only holds one thing with lots of layers of stuff on top of it.

    One more Question, I want to set Look&Feel to native, I know how to do it with UIManager, But what I'm asking is where to put it. If I make the JFrame's L&F native to the running system, will the whole thing have that L&F? Or do I have to set each one's. But I don't know where to put the code that sets L&F if the class doesn't have main method (everything but the frame).
    I usually don't mess with L&F, so someone else would be better equipped to answer this.

    netbeans makes the class files in the build directory, then theres like 7 more for some of them that say classname$1, then classname$2, etc. What is that?
    Those are the anonymous inner classes
    next question, I explained my packages already, packageone, packageone.components (relied apon classes), packageone.gui. Should I keep my JFrame class in the packageone, or with the gui's, so that I don't have to import them, and whatever other reasons there are. But then the packageone would have nothing in it, so would there be a point to it
    In your small app, it probably makes little difference here, but as your apps grow, packages can help you divide and conquer, and can help with keeping reusable bits that all act in a similar way or in a similar portion of the program, together in one logical entity.

Page 1 of 2 12 LastLast

Similar Threads

  1. ResultSet size
    By bugger in forum JDBC
    Replies: 18
    Last Post: 06-25-2011, 08:36 PM
  2. File size
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-19-2007, 09:27 AM
  3. Object size
    By kavithas in forum New To Java
    Replies: 0
    Last Post: 11-30-2007, 12:00 PM
  4. how to set an image size
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:27 PM
  5. how to set the value of BUFFER SIZE
    By oregon in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:16 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
  •