August 16, 2012

Access outer class members from inner class

The following example shows how to access outer class members from inner class
public class OuterClass{

   public void method() {
      //do something
   }

   class InnerClass {

      public void innerMethod() {
          OuterClass.this.method();
         //do something
      }
   }
}

August 8, 2012

Right align tabs in JTabbedPane

Some useful tips for aligning tabs in JTabbedPane :-

Align tabs to right
pnlMainTabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
Place tabs on right of the JTabbedPane

pnlMainTabbedPane.setTabPlacement(JTabbedPane.RIGHT)

August 7, 2012

Java Swing UI Settings

To set global UI settings in Java Swing, use UIManager and set the properties as needed. All components have their respective keys and default values. For a complete list of properties, refer http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html

These settings should be done before creating the JFrame where all these components are put into.

Example :
UIManager.put("Button.background", Color.RED);
UIManager.put("Button.font", new FontUIResource(new Font("Arial", Font.BOLD, 12)));