JPanel with JScrollPane

JScrollPane JScrollPane is a lightweight container that automatically handles the scrolling of another component. The component being scrolled can either be an individual component, such a table, or a group of  components contained within another lightweight container, such as a JPanel. Program       Program Source import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JScrollPane; … Read more…

JTabbedPane

The JTabbedPane control is available in Swing. This component appears as a group of folders in a file cabinet. Each folder has a title. When a user selects a folder, its contents become visible. Only one of the folders can be selected at a time. void addTab ( String str, Component comp) Here, str is … Read more…

JPanel with setPreferredSize and Dimension

To set the preferred size for each JPanel object, you call its setPreferredSize() method. The argument is a Dimension object that specifies the width and height. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.BorderFactory; import java.awt.Dimension; import java.awt.FlowLayout; class Frame extends JFrame { Frame() { setTitle(“setPreferredSize”); setLayout(new FlowLayout()); setJPanelOne(); … Read more…

JPanel with BoxLayout

BoxLayout arranges components either in a row or in a column. The BoxLayout constructor requires two arguments. The first is a reference to the container to which the layout manager applies, and the second is a constant that can be either BoxLayout. X_AXIS for a row-wise arrangement or BoxLayout.Y_AXIS for a column-wise arrangement. Program   … Read more…

JPanel,Color,setBackground,setBorder,createLineBorder,createMatteBorder

Border is the Swing interface that encapsulates a border. You can obtain a border by calling one of the factory methods defined by the BorderFactory class. The one used in the program is createLineBorder( ), which creates a simple line border. It is shown here: static Border createLineBorder(Color clr, int width) Here, clr specifies the … Read more…

JPanel and BorderFactory

The JPanel class defines something like a physical panel that you can use as a container to group a set of components. However, you can also place a component to which you want to add a border in a JPanel container, and add the border to the JPanel object. You decorate the panel with a … Read more…