Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Swing application with no real design pattern. I want to start learning to design Swing or any types of application properly. Here is the main JFrame class.

    import java.awt.Component;
    import java.awt.Dimension;    
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import org.text.gui.components.tabs.*;

    public class TextFrame extends JFrame {

        private static final long serialVersionUID = 1289484372051624149L;
        public static final String INBOX = "Inbox";
        public static final String CONTACT = "Contact";
        public static final String SEND = "Send";
        private JTabbedPane pane;

        public TextFrame() {

        public Component getTab(String title) {
        return pane.getComponentAt(pane.indexOfTab(title));

    public void setSelectedTab(String title) {

    private void initComponents() {
        pane = new JTabbedPane();
        pane.setPreferredSize(new Dimension(225, 300));
        pane.addTab(INBOX, new InboxTab(this));
        pane.addTab(CONTACT, new ContactTab(this));
        pane.addTab(SEND, new SendTab());

    private void layoutComponents() {

The tabs are JPanels with some logic in them. Any advice on a design pattern to implement or examples or anything would be greatly appreciated. I hope I included enough information.

share|improve this question
This appears to be a pretty clean implementation of the top frame. Seeing the code for the tabs (Inbox/Contact/etc) would shed more light on what's going on here and maybe more opportunity for review. – Eric P. Feb 25 '13 at 3:03
One thing which could be discussed, if it is a better way to extend JFrame or to have a private member of type JFrame. I prefer the second. Other than that I would agree to @E-Man – tb- Feb 27 '13 at 17:32
up vote 2 down vote accepted

One thing would be to separate view from functionality (you may even make the business logic invocation asynchronous). You can also make your code cleaner and smaller by creating widgets that support templating and using them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.