Component.getgraphics null




















Module java. Package javax. Object java. Component java. Container java. Window java. Frame javax. An extended version of java. Modifier and Type. This class implements accessibility support for the JFrame class. Frame Frame. Window Window. Container Container. Component Component. BaselineResizeBehavior , Component. BltBufferStrategy , Component. If true then calls to add and setLayout will be forwarded to the contentPane.

Fields declared in class java. Fields declared in interface java. Fields declared in interface javax. Constructs a new frame that is initially invisible. Creates a Frame in the specified GraphicsConfiguration of a screen device and a blank title. Creates a new, initially invisible Frame with the specified title. Creates a JFrame with the specified title and the specified GraphicsConfiguration of a screen device. Adds the specified child Component.

Called by the constructor methods to create the default rootPane. This method actually delegates the work of painting to three protected methods: paintComponent , paintBorder , and paintChildren.

They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI look and feel delegate's paint method should just override paintComponent.

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. You can detect changes in the value of this property by listening for property change events on this component with name "paintingForPrint".

Note: This method provides complimentary functionality to that provided by other high level Swing printing APIs. However, it deals strictly with painting and should not be confused as providing information on higher level print processes. For example, a JTable. It is even possible for the component to be painted to the screen while the printing process is ongoing.

In such a case, the return value of this method is true when, and only when, the table is being painted as part of the printing process. Also prevents SortingFocusTraversalPolicy from considering descendants of this JComponent when computing a focus traversal cycle. Overrides the default FocusTraversalPolicy for this JComponent 's focus traversal cycle by unconditionally setting the specified Component as the next Component in the cycle, and this JComponent as the specified Component 's previous Component in the cycle.

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow.

Instead we recommend the use of requestFocusInWindow boolean. This method is intended for use by focus implementations. Client code should not use this method; instead, it should use requestFocusInWindow. Although technically you can set the border on any object that inherits from JComponent , the look and feel implementation of many standard Swing components doesn't work well with user-set borders.

In general, when you want to set a border on a standard Swing component other than JPanel or JLabel , we recommend that you put the component in a JPanel and set the border on the JPanel. Register a new keyboard action. The KeyStroke object defines a particular combination of a keyboard key and one or more modifiers alt, shift, ctrl, meta.

Note that the component need not be an immediate descendent of the window -- it can be anywhere in the window's containment hierarchy. In other words, whenever any component in the window has the focus, the action registered with this component is invoked. In other words, in any hierarchical structure of components, an arbitrary key-combination can be immediately directed to the appropriate component in the hierarchy, and cause a specific method to be invoked usually by way of adapter objects.

If an action has already been registered for the receiving container, with the same charCode and the same modifiers, anAction will replace the action.

Unregisters a keyboard action. This will remove the binding from the ActionMap if it exists as well as the InputMap s. For Java 2 platform v1. This method calls into the ComponentUI method of the same name. If this component does not have a ComponentUI -1 will be returned. OTHER will be returned.

Subclasses should never return null ; if the baseline can not be calculated return BaselineResizeBehavior. It is acceptable for this method to return a value other than BaselineResizeBehavior. This method is implemented to do nothing. Subclasses would normally override this method if they process some key events themselves. If the event is processed, it should be consumed. If the new TransferHandler is not null , this method also installs a new DropTarget on the component to activate drop handling through the TransferHandler and activate any built-in support such as calculating and displaying potential drop locations.

If you do not wish for this component to respond in any way to drops, you can disable drop support entirely either by removing the drop target setDropTarget null or by de-activating it getDropTaget.

If the new TransferHandler is null , this method removes the drop target. Under two circumstances, this method does not modify the drop target: First, if the existing drop target on this component was explicitly set by the developer to a non-null value. Second, if the system property suppressSwingDropSupport is true.

The default value for the system property is false. For example, a layout manager might store per child constraints this way. For example: componentA. Changes to client properties are reported with PropertyChange events. The name of the property for the sake of PropertyChange events is key. The clientProperty dictionary is not intended to support large scale extensions to JComponent nor should be it considered an alternative to subclassing when designing a new component.

An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through".

Therefore, a component that does not fully paint its pixels provides a degree of transparency. Subclasses that guarantee to always completely paint their contents should override this method and return true.

The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses such as JButton and JTree is look-and-feel dependent.

You can specify the listenerType argument with a class literal, such as Foo Listener. Calls invalidate and then adds this component's validateRoot to a list of components that need to be validated. Validation will occur after all currently pending events have been dispatched. In other words after this method is called, the first validateRoot if any found when walking up the containment hierarchy of this component will be validated. This method will automatically be called on this component when a property value changes such that size, location, or internal layout of this component has been affected.

This automatic updating differs from the AWT because programs generally no longer need to invoke validate to get the contents of the GUI to update. Calling repaint long, int, int, int, int or paintImmediately int, int, int, int on a Swing component will result in calling the paintImmediately int, int, int, int method of the first ancestor which isPaintingOrigin returns true , if there are any.

JComponent subclasses that need to be painted when any of their children are repainted should override this method to return true. It's rarely necessary to call this method. In most cases it's more efficient to call repaint, which defers the actual painting and can collapse redundant requests into a single paint call. This method is useful if one needs to update the display while the current event is being dispatched. This method is to be overridden when the dirty region needs to be changed for components that are painting origins.

Module java. Package javax. Object java. Component java. Container javax. The base class for all Swing components except top-level containers. To use a component that inherits from JComponent , you must place the component in a containment hierarchy whose root is a top-level Swing container.

Top-level Swing containers -- such as JFrame , JDialog , and JApplet -- are specialized components that provide a place for other Swing components to paint themselves. Modifier and Type. Inner class of JComponent used to provide default support for accessibility. Container Container. Component Component. BaselineResizeBehavior , Component. BltBufferStrategy , Component. A list of event listeners for this component.

The comment to display when the cursor is over the component, also known as a "value tip", "flyover help", or "flyover label". The look and feel delegate for this component. Constant used by some of the APIs to mean that no condition is defined. Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.

Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus. Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component. Fields declared in class java. Fields declared in interface java. Default JComponent constructor. Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible or invisible.

Notifies this component that it now has a parent component. Neeraj jain wrote: Derek what was the problem? Derek Boring. Optional 'thank-you' note:. The getGraphics method in my constructor is returning a nullPointerException and I can't figure out why.

This class is extending a JPanel and I thought calling super would fix it because it makes sense that the JPanel would initialize its graphics object in the constructor, but that didn't fix it. The line that produces the error is in bold. A better alternative is to draw in a JComponent's paintComponent method and using the Graphics object passed into this method as its parameter. If you need to draw something that is to be a background image, also look into drawing on a BufferedImage.

When you do that, here you will call getGraphics on the image or createGraphics if you need a Graphics2D object , and here the object returned will be stable.



0コメント

  • 1000 / 1000