Raja has Published 760 Articles

How can we set the background color to a JPanel in Java?

raja

raja

Updated on 10-Feb-2020 06:58:58

13K+ Views

A JPanel is a container and it is an invisible component in Java. The FlowLayout is a default layout for a JPanel. We can add most of the components like buttons, text fields, labels, table, list, tree and etc. to a JPanel. We can set a background color to JPanel by using the setBackground() ... Read More

What are the differences between a Font and a FontMetrics in Java?

raja

raja

Updated on 10-Feb-2020 06:57:14

1K+ Views

A Font class is used to set the screen fonts and it maps the characters of the language to their respective glyphs whereas a FontMetrics class defines a font metrics object, which encapsulates information about the rendering of a particular font on a particular screen.FontA Font class can be used to create an ... Read More

How can we catch a double click and enter key events for a JList in Java?

raja

raja

Updated on 10-Feb-2020 06:55:05

542 Views

A JList can extend JComponent class that allows the user to choose either a single or multiple selections. A JList can generate a ListSelectiionListener interface and it includes one abstract method valueChanged(). A JList can also generate a MouseListener interface to catch a double click event in the list and generates a KeyListener interface to catch an ... Read More

What are the differences between paint() method and repaint() method in Java?

raja

raja

Updated on 10-Feb-2020 06:52:01

6K+ Views

Paint() and Repaint()paint(): This method holds instructions to paint this component. In Java Swing, we can change the paintComponent() method instead of paint() method as paint calls paintBorder(), paintComponent() and paintChildren() methods. We cannot call this method directly instead we can call repaint().repaint(): This method cannot be overridden. It controls the ... Read More

What is the importance of JSeparator class in Java?

raja

raja

Updated on 10-Feb-2020 06:49:41

151 Views

JSeparatorA JSeparator is a horizontal or vertical line or an empty space that separates the components.A JSeparator class is used to draw a line to separate the components in a Layout.The easiest way to add a separator to a menu or toolbar is to call the addSeparator() method provided by the classes JMenu, JPopupMenu and JToolBar.The important methods of ... Read More

How to display a bold text inside the JTextArea in Java?

raja

raja

Updated on 10-Feb-2020 06:47:37

1K+ Views

A JTextArea class can extend JTextComponent and allow a user to enter multiple lines of text inside it. A JTextArea can generate a CaretListener interface, which can listen to caret update events. We can set a font to a text inside the JTextArea by using setFont() method.Exampleimport java.awt.*; import javax.swing.*; public class ... Read More

How to change each column width of a JTable in Java?

raja

raja

Updated on 10-Feb-2020 06:45:38

7K+ Views

JTableA JTable is a subclass of JComponent for displaying complex data structures.A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns.The DefaultTableModel class can extend AbstractTableModel and it can be used to add the rows and columns to a JTable dynamically.The DefaultTableCellRenderer class can extend JLabel class and it can be ... Read More

How can we set the shortcut key to a JButton in Java?

raja

raja

Updated on 10-Feb-2020 06:43:17

1K+ Views

A JButton is a subclass of AbstractButton and it can be used for adding platform-independent buttons to a Java Swing application. A JButon can generate an ActionListener interface when the button is pressed or clicked, it can also generate the MouseListener and KeyListener interfaces. We can also set the short cut keys for a JButton using ... Read More

How can we implement a scrollable JPanel in Java?

raja

raja

Updated on 10-Feb-2020 06:35:13

4K+ Views

JPanelA JPanel is a subclass of JComponent (a subclass of a Container class). Therefore, JPanel is also a Container.A JPanel is an empty area that can be used either to layout other components including other panels.In a JPanel, we can add fields, labels, buttons, checkboxes,  and images also.The Layout Managers such ... Read More

How can we implement editable JComboBox in Java?

raja

raja

Updated on 10-Feb-2020 06:34:10

1K+ Views

JComboBoxA JComboBox can extend JComponent class and it is a combination of a text field and a drop-down list from which the user can choose a value.If the text field portion of the control is editable, the user can enter a value in the field or edit a value retrieved from ... Read More

Advertisements