SwingJD project: CollapsablePanel
Thursday, December 06, 2012SwingJD project: CollapsablePanel
· CollapasablePanel is a Java Swing custom element that collapses/expands the upper and lower arrow clicks.
The CollapasablePane is basically 2 parts.
1) TopPanel
2) ContentPanel
This is a custom JPanel.
Is simple stretching and JPanel replaces the paintComponent method.
public class extends JPanel TopPanel;
All logic associated with the HeadingPanel is under the
@ Override
{public void paintComponent (Graphics g)
Graphics2D g2d = g. create () (Graphics2D);
g2d. setRenderingHint (KEY _ANTIALIASING, RenderingHints.
RenderingHints. VALUE_ANTIALIAS_ON);
createPanelImage ();
g2d. drawImage (panelImage, null, 0, 0);
}
Things to do in paintComponent method ()
o create a table image
/**
* Creates the image of the table.
*/
{private void createPanelImage ()
panelImage = new BufferedImage (getWidth (), getHeight (),
BufferedImage. TYPE_INT_ARGB);
Graphics2D g2d = panelImage. createGraphics ();
g2d. setRenderingHint (KEY _ANTIALIASING, RenderingHints.
RenderingHints. VALUE_ANTIALIAS_ON);
g2d. setRenderingHint (java. awt. RenderingHints. KEY _TEXT_ANTIALIASING,
java. awt. RenderingHints. VALUE_TEXT_ANTIALIAS_ON);
drawShape (g2d);
} ·
Draw the shape of the table o
Background design and exterior rectangle
{private void drawShape (Graphics2D g2d)
int width = getWidth ();
int pnlHght = 30;
//Draw background and outer rectangle
If (themeType. equals ("GLOSSY")) {
contentPanel. setBorder (new LineBorder (new color (0, 0, 0, 50)));
g2d. setPaint (bgColor);
g2d. fillRect (0, startPoint, width, pnlHght);
g2d. setPaint (gradientPaint);
g2d. fillRect (2 + 2, startPoint, width-4, pnlHght/2);
g2d. setColor (new color (0, 0, 0, 150));
g2d. drawRect() (0, startPoint, width-1, pnlHght-1);
g2d. setColor (new color (255, 255, 255, 100));
g2d. drawRect() (1 + 1, startPoint, width-3, pnlHght-3);
} else {
g2d. setPaint (gradientPaint);
g2d. fillRect (0, startPoint, width, pnlHght);
g2d. setPaint (new color (50, 50, 50, 150));
g2d. drawRect() (0, startPoint, width-1, pnlHght-1);
g2d. setPaint (new color (255, 255, 255, 50));
g2d. drawRect() (1 + 1, startPoint, width-3, pnlHght-3);
}
}
o create the up/down arrow icon based isCollapsed status
To go for more information and source code to make the link below
CollapsablePanel
For more information and source code click on the following link
Posted by Jeeru (Dec 06, 2011, 10: 55: 18 AM EST) Permalink
View the original article here
Posted By Unknown
Blog Rating 5 dari 5
0 comments:
Post a Comment