Trending September 2023 # Methods And Different Examples Of Jdesktoppane # Suggested October 2023 # Top 9 Popular | Lifecanntwaitvn.com

Trending September 2023 # Methods And Different Examples Of Jdesktoppane # Suggested October 2023 # Top 9 Popular

You are reading the article Methods And Different Examples Of Jdesktoppane updated in September 2023 on the website Lifecanntwaitvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Methods And Different Examples Of Jdesktoppane

Introduction to JDesktopPane

JDesktopPane is a class available in the JavaFX that can be used for generating multi-documented interfaces, which can hold many windows or application pages. It is achieved by making use of the contentPane and JInternalFrame from the main window and internal window respectively.

Web development, programming languages, Software testing & others

JDesktopPane jdp = new JDesktopPane();

Where, JDesktopPane() acts as the constructor method used for making a new JDesktopPane.

Other methods used from the JDesktopPane are getUI(), remove(int i), removeAll(), getDragMode(), getAllFrame(), getUIClassID(), UpdateUI(), paramString(), setDragMode(int dm), selectFrame(Boolean fwd), etc.

Constructor:

It has only one constructor JDesktopPane() that helps in creating a new JDesktopPane.

Methods

It has numerous methods that perform several functionalities. Following are the commonly used methods of JDesktopPane:

getAllFrames(): JInternalFrames that is presently displayed in the desktop will be returned.

getAllFramesInLayer(int l): JInternalFrames that is presently displayed in the desktop on the specified layer l will be returned.

getDesktopManager(): Desktop manager that manages User Interface actions that are desktop specific will be returned.

getAccessibleContext(): AccessibleContext that is related to the JDesktopPane will be returned.

getUI(): Look and Feel object that renders the component will be returned.

remove(int i): Indexed component i will be removed from this pane.

removeAll(): Each and every component from the container will be removed.

getDragMode(): The style of dragging will be returned which is currently used by the desktop pane.

getSelectedFrame(): JInternalFrame will be returned which is currently active in the desktop pane. If no active JInternalFrame is present, then null will be returned.

setUI(DesktopPaneUIuserinterface): Look and Feel object that renders the component will be set.

setDragMode(int dm): Dragging style dm will be set in the desktop pane.

remove(Componentcmp): Component cmp from the container will be removed.

selectFrame(boolean fwd): JInternalFrame will be selected which is next in this desktop pane.

setSelectedFrame(JInternalFramejf): JInternalFrame will be set which is currently active in the desktop pane.

getUIClassID(): Name of the Look and Feel object that renders the component will be returned.

updateUI(): A notification that Looks and Feels object has changed will be updated from UIManager.

setDesktopManager(DesktopManagerd): DesktopManager will be set that handles User Interface actions of the desktop.

paramString( ): String representation will be returned for the JDesktopPane.

addImpl(Componentcmp, Object constr, int i): Specified component cmp will be added to the container at the index i.

Program to Implement JDesktopPane

Now, let us see different JavaFX programs:

Program #1 – Create JDesktopPane with 4 windows import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class JDesktopPaneExample extends JFrame { public JDesktopPaneExample() { CustomDesktopPane dp = new CustomDesktopPane(); Container cp = getContentPane(); cp.add(dp, BorderLayout.CENTER); dp.display(dp); setTitle("Example for JDesktopPane"); setSize(350,400); setVisible(true); } public static void  main(String args[]) { new JDesktopPaneExample(); } } class CustomDesktopPane extends JDesktopPane { int n = 4; int x = 40, y = 40; public void display(CustomDesktopPane dp) { for(int  i = 0; i < n ; ++i ) { JInternalFrame jf = new JInternalFrame("JInternal Frame no : " + i ,  true, true, true, true); jf.setBounds(x, y, 250, 60); Container cnt = jf.getContentPane( ) ; cnt.add(new JLabel("Sample label for demonstration ")); dp.add( jf ); jf.setVisible(true); y += 85; } } }

Output:

Here, a pane is displayed with 4 internal frames with 4 labels for demonstration. Suppose JInternalFrame no:0 is maximized, the result will be as shown below:

Similarly, all other windows can also be maximized like the above one.

Program #2 – Create with 1 internal frame import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class JDesktopPaneExample { public static void main(final String[] args) { JFrame fr = new JFrame(); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane dp = new JDesktopPane(); JInternalFrame iframe = new JInternalFrame("Sample frame for demo purpose", true, true, true, true); dp.add(iframe); iframe.setBounds(60, 100, 500, 260); JLabel lb = new JLabel(iframe.getTitle(), JLabel.CENTER); JButton btn = new JButton("Button for demo purpose"); iframe.add(lb, BorderLayout.EAST); iframe.add(btn, BorderLayout.WEST); iframe.setVisible(true); fr.add(dp, BorderLayout.CENTER); fr.setSize(650, 550); fr.setVisible(true); } }

Output:

On executing the code, a frame will be displayed with a button and a label inside it.

Conclusion

JDesktopPane is used in multi-document interfaces or applications which contain several windows in it. Many of the products are using this pane for their commercial purpose. The main products include Microsoft PowerPoint, Allaire HomeSite, Corel Draw, and Symantec Visual Café. In all these products, the main desktop pane will be present that contains all other windows. In order to use this pane, instantiate the class javafx.swing.JDesktopPane.

Recommended Articles

This is a guide to JDesktopPane. Here we discuss the syntax, constructors, used methods and different examples of JDesktopPane. You may also look at the following articles to learn more –

You're reading Methods And Different Examples Of Jdesktoppane

Update the detailed information about Methods And Different Examples Of Jdesktoppane on the Lifecanntwaitvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!