Add frame to frame java

Class JFrame

An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture. You can find task-oriented documentation about using JFrame in The Java Tutorial, in the section How to Make Frames.

The JFrame class is slightly incompatible with Frame . Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame . This is different from the AWT Frame case. As a convenience, the add , remove , and setLayout methods of this class are overridden, so that they delegate calls to the corresponding methods of the ContentPane . For example, you can add a child component to a frame as follows:

And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JFrame .

Unlike a Frame , a JFrame has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the JFrame when the user closes the window. To change the default behavior, you invoke the method setDefaultCloseOperation(int) . To make the JFrame behave the same as a Frame instance, use setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) .

For more information on content panes and other features that root panes provide, see Using Top-Level Containers in The Java Tutorial.

In a multi-screen environment, you can create a JFrame on a different screen device. See Frame for more information.

Warning: Swing is not thread safe. For more information see Swing’s Threading Policy.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .

Источник

Java Swing | Internal Frame with examples

JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc.
Constructors for JInternalFrame

  1. JInternalFrame() : creates a new non- closable, non- resizable, non- iconifiable, non- maximizable JInternalFrame with no title
  2. JInternalFrame(String t) :creates a new non- closable, non- resizable, non- iconifiable, non- maximizable JInternalFrame with a title specified
  3. JInternalFrame(String t, boolean resizable) :creates a new non- closable, non- iconifiable, non- maximizable JInternalFrame with a title and resizability specified
  4. JInternalFrame(String t, boolean resizable, boolean closable) : creates a new non- iconifiable, non- maximizable JInternalFrame with a title, closability and resizability specified
  5. JInternalFrame(String t, boolean resizable, boolean closable, boolean maximizable) :creates a new non- iconifiable JInternalFrame with a title, closability, maximizability and resizability specified
  6. JInternalFrame(String t, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) : creates a new JInternalFrame with a title, closability, maximizability, iconifiability and resizability specified
Читайте также:  Тень для объекта css

Commonly used methods

  1. setFrameIcon(Icon icon) : sets the icon for the frame to the specified image
  2. setLayout(LayoutManager manager) : sets the layout of the frame to specified layout manager
  3. setTitle(String t): set the title of the frame to specified title
  4. getTitle() : get the title of the frame
  5. reshape(int x, int y, int width, int height) : resize the frame to specified width and height and a specified location
  6. add(Component c) : adds the specified component to the container.
  7. addImpl(Component c, Object co, int i) : adds the specified component.
  8. addInternalFrameListener(InternalFrameListener l) : adds the specified InternalFrameListener to the list.
  9. createRootPane() : called by the constructor to set up the JRootPane.
  10. dispose() : makes this internal frame invisible, unselected, and closed.
  11. fireInternalFrameEvent(int id) : fires an internal frame event.
  12. getAccessibleContext() : gets the AccessibleContext associated with this JInternalFrame.
  13. getContentPane() : returns the content pane for this internal frame.
  14. getDefaultCloseOperation() : returns the default operation that occurs when the user initiates a “close” on this internal frame.
  15. getDesktopIcon() : returns the JDesktopIcon used when this JInternalFrame is iconified.
  16. getDesktopPane() : convenience method that searches the ancestor hierarchy for a JDesktop instance.
  17. getFocusOwner() : If this JInternalFrame is active, returns the child that has focus.
  18. getFrameIcon() : returns the image displayed in the title bar of this internal frame
  19. getGlassPane() : returns the glass pane for this internal frame.
  20. getInternalFrameListeners() : Returns an array of all the InternalFrameListeners added to this JInternalFrame with addInternalFrameListener
  21. getJMenuBar() : returns the current JMenuBar for this JInternalFrame
  22. getLastCursor() : returns the last Cursor that was set by the setCursor method
  23. getLayer() : convenience method for getting the layer attribute of this component.
  24. getLayeredPane() : returns the layered pane for this internal frame.
  25. getMostRecentFocusOwner() : returns the child component of this JInternalFrame that will receive the focus when this JInternalFrame is selected.
  26. getNormalBounds() : If the JInternalFrame is not in maximized state, returns getBounds(); otherwise, returns the bounds that the JInternalFrame would be restored to.
  27. getRootPane(): returns the rootPane object for this internal frame.
  28. getUI() : returns the look-and-feel object that renders this component.
  29. getWarningString() : gets the warning string that is displayed with this internal frame.
  30. isClosable() : returns whether this JInternalFrame can be closed by some user action.
  31. isClosed() : Returns whether this JInternalFrame is currently closed.
  32. isIcon() : returns whether the JInternalFrame is currently iconified.
  33. isMaximizable() : gets the value of the maximizable property.
  34. isMaximum() : returns whether the JInternalFrame is currently maximized.
  35. isResizable() : returns whether the JInternalFrame can be resized or not.
  36. isSelected() : returns whether the JInternalFrame is the currently active frame or not.
  37. pack() : causes components of this JInternalFrame to be laid out at their preferred size.
  38. paintComponent(Graphics g) : Overridden to allow optimized painting when the internal frame is being dragged.
  39. paramString() : Returns a string representation of this JInternalFrame.
  40. remove(Component c) : removes the specified component from the container.
  41. removeInternalFrameListener(InternalFrameListener l) : removes the specified internal frame listener.
  42. setClosable(boolean b) : sets whether this JInternalFrame can be closed by some user action.
  43. setContentPane(Container c) : sets this JInternalFrame’s contentPane property.
  44. setCursor(Cursor c) : sets the cursor image to the specified cursor.
  45. setDefaultCloseOperation(int o): sets the operation that will happen by default when the user initiates a “close” on this internal frame.
  46. setDesktopIcon(JInternalFrame.JDesktopIcon d) : sets the JDesktopIcon associated with this JInternalFrame.
  47. setGlassPane(Component g) : sets this JInternalFrame’s glassPane property.
  48. setIcon(boolean b) : Iconifies or de-iconifies this internal frame.
  49. setJMenuBar(JMenuBar m) : sets the menuBar property for this JInternalFrame.
  50. setIconifiable(boolean b) : sets the iconable property, which must be true for the user to be able to make the JInternalFrame an icon.
  51. setJMenuBar(JMenuBar m) : sets the menuBar property for this JInternalFrame.
  52. setLayer(int l) : convenience method for setting the layer attribute of this component.
  53. setLayer(Integer l) : convenience method for setting the layer attribute of this component.
  54. setLayeredPane(JLayeredPane l) : sets this JInternalFrame’s layeredPane property.
  55. setMaximizable(boolean b) : sets the maximizable property, which determines whether the JInternalFrame can be maximized by some user action.
  56. setMaximum(boolean b) : Maximizes and restores this internal frame.
  57. setNormalBounds(Rectangle r) : sets the normal bounds for this internal frame.
  58. setResizable(boolean b) :sets whether the JInternalFrame can be resized by some user action.
  59. setRootPane(JRootPane r) : sets the rootPane property for this JInternalFrame.
  60. setRootPaneCheckingEnabled(boolean e) : sets whether calls to add and setLayout are forwarded to the contentPane.
  61. setSelected(boolean s) : selects or deselects the internal frame if it’s showing.
  62. setUI(InternalFrameUI ui) : sets the UI delegate for this JInternalFrame.
  63. show() : makes the internal frame visible.
  64. toBack(): sends this internal frame to the back.
  65. toFront() : Brings this internal frame to the front.
  66. updateUI() : notification from the UIManager that the look and feel has changed.
Читайте также:  Delete field in object javascript

1. Program to create a simple JInternalFrame :

Источник

Class JFrame

An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture. You can find task-oriented documentation about using JFrame in The Java Tutorial, in the section How to Make Frames.

The JFrame class is slightly incompatible with Frame . Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame . This is different from the AWT Frame case. As a convenience, the add , remove , and setLayout methods of this class are overridden, so that they delegate calls to the corresponding methods of the ContentPane . For example, you can add a child component to a frame as follows:

And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JFrame .

Unlike a Frame , a JFrame has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the JFrame when the user closes the window. To change the default behavior, you invoke the method setDefaultCloseOperation(int) . To make the JFrame behave the same as a Frame instance, use setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) .

For more information on content panes and other features that root panes provide, see Using Top-Level Containers in The Java Tutorial.

In a multi-screen environment, you can create a JFrame on a different screen device. See Frame for more information.

Читайте также:  Задать высоту html css

Warning: Swing is not thread safe. For more information see Swing’s Threading Policy.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .

Источник

Оцените статью