Home » Desktop Java » swing

swing

Set tab color in JTabbedPane

With this example we shall see how to set tab color in JTabbedPane. In order to do that, one should follows these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.setForeground(Color.green) to set foreground color. Use tabbedPane.setBackground(Color.red) to set the background color. Use tabbedPane.addTab to add a tool tip. Let’s see the code: package ...

Read More »

Remove tab in JTabbedPane

With this example we shall see how to  remove a tab from a JTabbedPane. In order to do that, one should follow these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.remove(2) to remove the third tab for instance Use tabbedPane.addTab to add a tool tip. Let’s see the code: package com.javacodegeeks.snippets.desktop; import java.awt.GridLayout; ...

Read More »

Get tab info in JTabbedPane

In this example we are going to see how to get the tab info in a JTabbedPane component of a Java Desktop Application. Basically all you have to do for it is to: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.addTab to add a tab. Use tabbedPane.getTabCount() to get the number of tabs. ...

Read More »

Get/Set selected tab in JTabbedPane

With this tutorial we shall show you how to get or set the selected tab in a JTabbedPane component of a Java Desktop Application. Basically all you have to do for it is to: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.getSelectedIndex() to get the index of the selected tab. Use tabbedPane.setSelectedIndex() ...

Read More »

Enable scrolling tabs in JTabbedPane

With this example we shall show you how to enable scrolling in a JTabbedPane component of a Java Desktop Application. In order to do that you just have to follow these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.addTab to add a tab. Use tabbedPane.getTabRunCount() to get the number of tabs. Use tabbedPane.getTabLayoutPolicy() to ...

Read More »

Add tab to JTabbedPane

In this tutorial we are going to see how to add a tab to a JTabbedPane component of a Java Desktop Application. Basically, all you have to do is: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.addTab to add a tab.   Let’s see the code: package com.javacodegeeks.snippets.desktop; import java.awt.GridLayout; import javax.swing.Icon; import ...

Read More »

Create JTabbedPane example

With this example we shall show you how to create a JTabbedPane component in a Java Desktop Application. This is a very important GUI component in a graphical application, because it lets you create very easy to use interfaces and enable the user to provide input to the application easily and all in all it’s quite an elegant way to ...

Read More »

Get/Set divider size in JSplitPane

This is an example on how to get or set the size of the divider in a JSplitPane component of a Java Desktop Application. In order to do that you have to follow these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new FlowLayout()) to set flow layout for the frame. Create two String arrays that will containt the contents of the ...

Read More »

Get/Set divider location in JSplitPane

In this example on how to get or set the location of the divider in a JSplitPane component of a Java Desktop Application. In order to do that you have to follow these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new FlowLayout()) to set flow layout for the frame. Create two String arrays that will containt the contents of the two areas of theJSplitPane. Create ...

Read More »

Create JSplitPane example

This is an example on how to create a new JSplitPane component for a Java Desktop Application.The JSplitPane is commonly used component because it lets you split your window horizontally or vertically in order to create a wide variety of GUI elements to suit your application’s needs. In short in order to create a JSplitPane component in Java, one should ...

Read More »