title: How to use Guice in Swing application
body: <p>I have a Swing application that I would like to convert from spaghetti to using dependency injection with Guice. Using Guice to provide services like configuration and task queues is going great but I'm now starting on the GUI of the app and am unsure of how to proceed.</p>
  
  <p>The application is basically a <code>JFrame</code> with a bunch of tabs in a <code>JTabbedPane</code>. Each of the tabs is a separate <code>JPanel</code> subclass that lays out the various components and needs services to perform actions when certain buttons are pressed.</p>
  
  <p>In the current application, this looks somewhat like this:</p>
  
  <pre><code>@Inject
  public MainFrame(SomeService service, Executor ex, Configuration config) {
      tabsPane = new JTabbedPane();
  
      // Create the panels for each tab and add them to the tabbedpane
      somePanel = new SomeTabPanel(service, ex, config);
      tabsPane.addTab("Panel 1", somePanel);
  
      someOtherPanel = new SomeOtherTabPanel(service, ex, config);
      tabsPane.addTab("Panel 2", someOtherPanel);
  
      ... do more stuff
  }
  </code></pre>
  
  <p>Obviously, this doesn't exactly follow DI best practices. I don't want to have to <code>@Inject</code> the tabs because that would get me a constructor with dozens of parameters. I do want to use Guice to inject the required dependencies into whatever tab objects I need without me having to pass all of those dependencies to the tab constructors.</p>
  
  <p>All of the dependencies for the tab objects are services that my <code>Module</code> knows about, so basically all I <em>think</em> I want to do is to ask Guice for the required objects and have them constructed for me. </p>