为窗口添加状态栏,窗口添加状态栏,public class
分享于 点击 15445 次 点评:58
为窗口添加状态栏,窗口添加状态栏,public class
public class JStatusPanel extends JPanel { public JStatusPanel( ){ setPreferredSize(new Dimension(getWidth( ), 23)); } public 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); y++; g.setColor(new Color(218, 215, 201)); g.drawLine(0, y, getWidth( ), y); y++; g.setColor(new Color(233, 231, 217)); g.drawLine(0, y, getWidth( ), y); y = getHeight( ) - 3; g.setColor(new Color(233, 232, 218)); g.drawLine(0, y, getWidth( ), y); y++; g.setColor(new Color(233, 231, 216)); g.drawLine(0, y, getWidth( ), y); y = getHeight( ) - 1; g.setColor(new Color(221, 221, 220)); g.drawLine(0, y, getWidth( ), y); } JLabel resizeIconLabel = new JLabel(new TriangleSquareWindowsCornerIcon( )); resizeIconLabel.setOpaque(false); JPanel rightPanel = new JPanel(new BorderLayout( )); rightPanel.setOpaque(false); rightPanel.add(resizeIconLabel, BorderLayout.SOUTH); add(rightPanel, BorderLayout.EAST); contentPanel = new JPanel( ); contentPanel.setOpaque(false); add(contentPanel, BorderLayout.CENTER); layout = new com.jgoodies.forms.layout.FormLayout( "2dlu, pref:grow", "3dlu, fill:10dlu, 2dlu"); contentPanel.setLayout(layout); public void setMainLeftComponent(JComponent component){ contentPanel.add(component, new CellConstraints(2, 2)); } } public class SeparatorPanel extends JPanel { private Color leftColor; private Color rightColor; public SeparatorPanel(Color left, Color right) { this.leftColor = left; this.rightColor = right; setOpaque(false); } protected void paintComponent(Graphics g) { g.setColor(leftColor); g.drawLine(0,0, 0,getHeight( )); g.setColor(rightColor); g.drawLine(1,0, 1,getHeight( )); } public void addRightComponent(JComponent component, int dialogUnits){ layout.appendColumn(new ColumnSpec("2dlu")); layout.appendColumn(new ColumnSpec(dialogUnits + "dlu")); layoutCoordinateX++; contentPanel.add( new SeparatorPanel(Color.GRAY, Color.WHITE), new CellConstraints(layoutCoordinateX, layoutCoordinateY) ); layoutCoordinateX++; contentPanel.add( component, new CellConstraints(layoutCoordinateX, layoutCoordinateY) );}} public class StatusBarSimulator { public static void main(String[] args) { try { UIManager.setLookAndFeel(new WindowsLookAndFeel( )); } catch (Exception e){ } JFrame frame = new JFrame( ); frame.setBounds(200,200, 600, 200); frame.setTitle("Status bar simulator"); Container contentPane = frame.getContentPane( ); contentPane.setLayout(new BorderLayout( )); JStatusBar statusBar = new JStatusBar( ); JLabel leftLabel = new JLabel("Your application is about to self destruct."); statusBar.setMainLeftComponent(leftLabel); JLabel dateLabel = new JLabel("12/31/99"); dateLabel.setHorizontalAlignment(SwingConstants.CENTER); statusBar.addRightComponent(dateLabel, 30); JLabel timeLabel = new JLabel("11:59 PM"); timeLabel.setHorizontalAlignment(SwingConstants.CENTER); statusBar.addRightComponent(timeLabel, 30); contentPane.add(statusBar, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show( ); }}//该片段来自于http://byrx.net
用户点评