X

Geertjan's Blog

  • March 6, 2014

Sidebar for NetBeans Platform Applications

Geertjan Wielenga
Product Manager
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.border.LineBorder;
import org.openide.windows.OnShowing;
import org.openide.windows.WindowManager;
@OnShowing
public class Startable implements Runnable {
@Override
public void run() {
Frame mainWindow = WindowManager.getDefault().getMainWindow();
Container contentPane =
((JRootPane) mainWindow.getComponents()[0]).getContentPane();
contentPane.add(BorderLayout.WEST, new SideBarPanel());
}
private class SideBarPanel extends JPanel {
public SideBarPanel() {
setPreferredSize(new Dimension(40, 40));
setBorder(new LineBorder(Color.RED, 2));
}
}
}

The result is the red border on the left of the screenshot below, which could just as easily be BorderLayout.EAST, of course, or any other place:

On the NetBeans Platform mailing list, Djamel Torche from Algeria recently showed off a screenshot of an app that has a sidebar on which the solution above is based:


Join the discussion

Comments ( 1 )
  • Jhonse Friday, March 7, 2014

    very good!


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha