|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.tentackle.print.PrintPanel
public class PrintPanel
A printing panel.
PrintPanel is a JPanel with some methods overridden to make it printable. Furthermore, a PrintPanel is also a Printable with a minimalistic print-implementation (prints a single page).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.print.Printable |
|---|
NO_SUCH_PAGE, PAGE_EXISTS |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
PrintPanel()
Creates a print panel. |
|
PrintPanel(LayoutManager layout)
Creates a print panel with a Layout-Manager (default is FlowLayout) |
|
| Method Summary | |
|---|---|
void |
doLayout()
Causes this container to lay out its components. |
Dimension |
getDynamicSize()
Calculates the dynamic size. The dynamic size may vary from the current size as some components (usually PrintTextAreas) may change their size according to
their contents. |
Dimension |
getPreferredSize()
Gets the preferred size. If the prefererredSize has already been set (and its witdh and height is not zero) that size will be returned. Otherwise the method calculates the preferred size as the smallest bounding box around all components. |
void |
pack()
Packs the components and this panel. |
void |
packHeightForWidth(int width)
Same as pack(), but pack only vertically and set the width to a fixed size |
void |
packWidthForHeight(int height)
Same as pack(), but pack only horizontally and set the width to a fixed size |
void |
print(Graphics g)
Prints the panel with all its components. |
int |
print(Graphics graphics,
PageFormat pageFormat,
int pageIndex)
Prints this panel on a single page. |
void |
repaint()
Overridden to do nothing |
void |
revalidate()
Overridden to do nothing |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PrintPanel()
public PrintPanel(LayoutManager layout)
layout - the layout manager| Method Detail |
|---|
public void print(Graphics g)
Invoke this method to print the component to the specified
Graphics. This method will result in invocations
of printComponent, printBorder and
printChildren. It is recommended that you override
one of the previously mentioned methods rather than this one if
your intention is to customize the way printing looks. However,
it can be useful to override this method should you want to prepare
state before invoking the superclass behavior. As an example,
if you wanted to change the component's background color before
printing, you could do the following:
public void print(Graphics g) {
Color orig = getBackground();
setBackground(Color.WHITE);
// wrap in try/finally so that we always restore the state
try {
super.print(g);
} finally {
setBackground(orig);
}
}
Alternatively, or for components that delegate painting to other objects,
you can query during painting whether or not the component is in the
midst of a print operation. The isPaintingForPrint method provides
this ability and its return value will be changed by this method: to
true immediately before rendering and to false
immediately after. With each change a property change event is fired on
this component with the name "paintingForPrint".
This method sets the component's state such that the double buffer
will not be used: painting will be done directly on the passed in
Graphics.
print in class JComponentg - the Graphics context in which to paintJComponent.printComponent(java.awt.Graphics),
JComponent.printBorder(java.awt.Graphics),
JComponent.printChildren(java.awt.Graphics),
JComponent.isPaintingForPrint()public Dimension getDynamicSize()
PrintTextAreas) may change their size according to
their contents.
public Dimension getPreferredSize()
getPreferredSize in class JComponentpreferredSize propertyJComponent.setPreferredSize(java.awt.Dimension),
ComponentUIpublic void pack()
public void packHeightForWidth(int width)
width - the fixed widthpublic void packWidthForHeight(int height)
height - the fixed heightpublic void revalidate()
revalidate in class JComponentComponent.invalidate(),
Container.validate(),
JComponent.isValidateRoot(),
RepaintManager.addInvalidComponent(javax.swing.JComponent)public void repaint()
repaint in class ComponentComponent.update(Graphics)
public int print(Graphics graphics,
PageFormat pageFormat,
int pageIndex)
Prints the page at the specified index into the specified
Graphics context in the specified
format. A PrinterJob calls the
Printable interface to request that a page be
rendered into the context specified by
graphics. The format of the page to be drawn is
specified by pageFormat. The zero based index
of the requested page is specified by pageIndex.
If the requested page does not exist then this method returns
NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
The Graphics class or subclass implements the
PrinterGraphics interface to provide additional
information. If the Printable object
aborts the print job then it throws a PrinterException.
print in interface Printablegraphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawn
pageIndex specifies a
non-existent page.public void doLayout()
validate method instead.
For some reasons the validate()-method does not layout the container properly if it hasn't been displayed on the screen. So we re-implement doLayout() here. Because PrintPanels usually have a fixed size according to the papers Layout we run doLayout top-down (not bottom-up).
doLayout in class ContainerLayoutManager.layoutContainer(java.awt.Container),
Container.setLayout(java.awt.LayoutManager),
Container.validate()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||