Paint your own status bar : Status Bar « Swing Components « Java






Paint your own status bar

    

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

class JStatusBar extends JPanel {

  public JStatusBar() {
    setLayout(new BorderLayout());
    setPreferredSize(new Dimension(10, 23));

    JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.setOpaque(false);

    add(rightPanel, BorderLayout.EAST);
  }

  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    int y = 0;
    g.setColor(new Color(156, 154, 140));
    g.drawLine(0, y, getWidth(), y);
    y++;
    g.setColor(new Color(196, 194, 183));
    g.drawLine(0, y, getWidth(), y);
  }
}

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(600, 200);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());

    JStatusBar statusBar = new JStatusBar();
    contentPane.add(statusBar, BorderLayout.SOUTH);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

  }

}

   
    
    
    
  








Related examples in the same category

1.Status Bar Demo
2.Statusbar component
3.Single instance status bar
4.A status bar is made of multiple zones