Question
stringlengths
1
113
Answer
stringlengths
22
6.98k
Can you provide an example of Java JTable?
import javax.swing.*; public class TableExample { JFrame f; TableExample(){ f=new JFrame(); String data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]={"ID"...
Java JTable Example with ListSelectionListener
import javax.swing.*; import javax.swing.event.*; public class TableExample { public static void main(String[] a) { JFrame f = new JFrame("Table Example"); String data[][]={ {"101","Amit","670000"}, ...
What is Java JList?
The object of JList class represents a list of text items. The list of text items can be set up so that the user can choose either one item or multiple items. It inherits JComponent class.
What is JList class declaration?
public class JList extends JComponent implements Scrollable, Accessible
Can you provide an example of Java JList?
import javax.swing.*; public class ListExample { ListExample(){ JFrame f= new JFrame(); DefaultListModel<String> l1 = new DefaultListModel<>(); l1.addElement("Item1"); l1.addElement("Item2"); l1.addElement("Item3"); l1.addElement("I...
Can you provid a Java JList Example with ActionListener?
import javax.swing.*; import java.awt.event.*; public class ListExample { ListExample(){ JFrame f= new JFrame(); final JLabel label = new JLabel(); label.setSize(500,100); JButton b=new JButton("Show"); b.setBounds(200,150,80,30); ...
What is Java JOptionPane?
The JOptionPane class is used to provide standard dialog boxes such as message dialog box, confirm dialog box and input dialog box. These dialog boxes are used to display information or get input from the user. The JOptionPane class inherits JComponent class.
Can you provide an example of JOptionPane class declaration?
public class JOptionPane extends JComponent implements Accessible
Can you provide an example of Java JOptionPane: showMessageDialog()?
import javax.swing.*; public class OptionPaneExample { JFrame f; OptionPaneExample(){ f=new JFrame(); JOptionPane.showMessageDialog(f,"Hello, Welcome to Javatpoint."); } public static void main(String[] args) { new OptionPaneExample(); } }
Can you provide an example of Java JOptionPane: showInputDialog()?
import javax.swing.*; public class OptionPaneExample { JFrame f; OptionPaneExample(){ f=new JFrame(); String name=JOptionPane.showInputDialog(f,"Enter Name"); } public static void main(String[] args) { new OptionPaneExample(); } }
Can you provide an example of Java JOptionPane showConfirmDialog()?
import javax.swing.*; import java.awt.event.*; public class OptionPaneExample extends WindowAdapter{ JFrame f; OptionPaneExample(){ f=new JFrame(); f.addWindowListener(this); f.setSize(300, 300); f.setLayout(null); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); ...
What is Java JScrollBar?
The object of JScrollbar class is used to add horizontal and vertical scrollbar. It is an implementation of a scrollbar. It inherits JComponent class.
What is JScrollBar class declaration?
public class JScrollBar extends JComponent implements Adjustable, Accessible
Can you provide an example of Java JScrollBar?
import javax.swing.*; class ScrollBarExample { ScrollBarExample(){ JFrame f= new JFrame("Scrollbar Example"); JScrollBar s=new JScrollBar(); s.setBounds(100,100, 50,100); f.add(s); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]...
Can you provide an example of Java JScrollBar with AdjustmentListener
import javax.swing.*; import java.awt.event.*; class ScrollBarExample { ScrollBarExample(){ JFrame f= new JFrame("Scrollbar Example"); final JLabel label = new JLabel(); label.setHorizontalAlignment(JLabel.CENTER); label.setSize(400,100); final JScrollBar s=new J...
What are the Java JMenuBar, JMenu and JMenuItem?
The JMenuBar class is used to display menubar on the window or frame. It may have several menus. The object of JMenu class is a pull down menu component which is displayed from the menu bar. It inherits the JMenuItem class. The object of JMenuItem class adds a simple labeled menu item. The items used in a menu mu...
What is JMenu class declaration?
public class JMenu extends JMenuItem implements MenuElement, Accessible
What is JMenuItem class declaration?
public class JMenuItem extends AbstractButton implements Accessible, MenuElement
Can you provide an example of Java JMenuItem and JMenu?
import javax.swing.*; class MenuExample { JMenu menu, submenu; JMenuItem i1, i2, i3, i4, i5; MenuExample(){ JFrame f= new JFrame("Menu and MenuItem Example"); JMenuBar mb=new JMenuBar(); menu=new JMenu("Menu"); submenu=new ...
Can you provided an Example of creating Edit menu for Notepad?
import javax.swing.*; import java.awt.event.*; public class MenuExample implements ActionListener{ JFrame f; JMenuBar mb; JMenu file,edit,help; JMenuItem cut,copy,paste,selectAll; JTextArea ta; MenuExample(){ f=new JFrame(); cut=new JMenuItem("cut"); copy=new JMenu...
What is Java JPopupMenu?
PopupMenu can be dynamically popped up at specific position within a component. It inherits the JComponent class.
What is JPopupMenu class declaration?
public class JPopupMenu extends JComponent implements Accessible, MenuElement
Can you provide an example of Java JPopupMenu?
import javax.swing.*; import java.awt.event.*; class PopupMenuExample { PopupMenuExample(){ final JFrame f= new JFrame("PopupMenu Example"); final JPopupMenu popupmenu = new JPopupMenu("Edit"); JMenuItem cut = new JMenuItem("Cut"); JMenuItem copy = new J...
Can you provide an example Java JPopupMenu with MouseListener and ActionListener?
import javax.swing.*; import java.awt.event.*; class PopupMenuExample { PopupMenuExample(){ final JFrame f= new JFrame("PopupMenu Example"); final JLabel label = new JLabel(); label.setHorizontalAlignment(JLabel.CENTER); label.setSize(400,100); ...
What is Java JCheckBoxMenuItem?
JCheckBoxMenuItem class represents checkbox which can be included on a menu . A CheckBoxMenuItem can have text or a graphic icon or both, associated with it. MenuItem can be selected or deselected. MenuItems can be configured and controlled by actions.
Can you provide a Java JCheckBoxMenuItem Example?
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.AbstractButton; import javax.swing.Icon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import j...
What is Java JSeparator?
The object of JSeparator class is used to provide a general purpose component for implementing divider lines. It is used to draw a line to separate widgets in a Layout. It inherits JComponent class.
What is JSeparator class declaration?
public class JSeparator extends JComponent implements SwingConstants, Accessible
Can you provide an example of Java JSeparator?
import javax.swing.*; class SeparatorExample { JMenu menu, submenu; JMenuItem i1, i2, i3, i4, i5; SeparatorExample() { JFrame f= new JFrame("Separator Example"); JMenuBar mb=new JMenuBar(); menu=new JMenu("Menu"); ...
What is Java JProgressBar?
The JProgressBar class is used to display the progress of the task. It inherits JComponent class.
What is JProgressBar class declaration?
public class JProgressBar extends JComponent implements SwingConstants, Accessible
Can you provide an example of Java JProgressBar?
import javax.swing.*; public class ProgressBarExample extends JFrame{ JProgressBar jb; int i=0,num=0; ProgressBarExample(){ jb=new JProgressBar(0,2000); jb.setBounds(40,40,160,30); jb.setValue(0); jb.setStringPainted(true); add(jb); setSize(250,150); setLayou...
What is Java JTree?
The JTree class is used to display the tree structured data or hierarchical data. JTree is a complex component. It has a 'root node' at the top most which is a parent for all nodes in the tree. It inherits JComponent class.
What is JTree class declaration?
public class JTree extends JComponent implements Scrollable, Accessible
Can you provide an example of Java JTree?
import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; public class TreeExample { JFrame f; TreeExample(){ f=new JFrame(); DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style"); DefaultMutableTreeNode color=new DefaultMutableTreeNode("color"); DefaultMu...
What is Java JColorChooser?
The JColorChooser class is used to create a color chooser dialog box so that user can select any color. It inherits JComponent class.
What is JColorChooser class declaration?
public class JColorChooser extends JComponent implements Accessible
Can you provide an example of Java JColorChooser?
import java.awt.event.*; import java.awt.*; import javax.swing.*; public class ColorChooserExample extends JFrame implements ActionListener { JButton b; Container c; ColorChooserExample(){ c=getContentPane(); c.setLayout(new FlowLayout()); b=new JButton("co...
Can you provide an example in Java JColorChooser with ActionListener?
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ColorChooserExample extends JFrame implements ActionListener{ JFrame f; JButton b; JTextArea ta; ColorChooserExample(){ f=new JFrame("Color Chooser Example."); b=new JButton("Pad Color"); b.setBounds...
What is Java JTabbedPane?
The JTabbedPane class is used to switch between a group of components by clicking on a tab with a given title or icon. It inherits JComponent class.
What is JTabbedPane class declaration?
public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants
Can you provide an example Java JTabbedPane?
import javax.swing.*; public class TabbedPaneExample { JFrame f; TabbedPaneExample(){ f=new JFrame(); JTextArea ta=new JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JTabbedPane tp=new JTabbedPane(); ...
What is Java JSlider?
The Java JSlider class is used to create the slider. By using JSlider, a user can select a value from a specific range.
Can you provide an example of Java JSlider?
import javax.swing.*; public class SliderExample1 extends JFrame{ public SliderExample1() { JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25); JPanel panel=new JPanel(); panel.add(slider); add(panel); } public static void main(String s[]) { SliderExample1 frame=new SliderExample...
Can you provide an example of Java JSlider: painting ticks?
import javax.swing.*; public class SliderExample extends JFrame{ public SliderExample() { JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25); slider.setMinorTickSpacing(2); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.setPaintLabels(true); JPanel panel=new JPan...
What is Java JSpinner?
The object of JSpinner class is a single line input field that allows the user to select a number or an object value from an ordered sequence.
What is JSpinner class declaration?
public class JSpinner extends JComponent implements Accessible
Can you provide an example of Java JSpinner?
import javax.swing.*; public class SpinnerExample { public static void main(String[] args) { JFrame f=new JFrame("Spinner Example"); SpinnerModel value = new SpinnerNumberModel(5, //initial value 0, //minimum value 10, //maximum value ...
Can you provide an example of Java JSpinner with ChangeListener?
import javax.swing.*; import javax.swing.event.*; public class SpinnerExample { public static void main(String[] args) { JFrame f=new JFrame("Spinner Example"); final JLabel label = new JLabel(); label.setHorizontalAlignment(JLabel.CENTER); la...
What is Java JDialog?
The JDialog control represents a top level window with a border and a title used to take some form of input from the user. It inherits the Dialog class. Unlike JFrame, it doesn't have maximize and minimize buttons.
What is JDialog class declaration?
public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer
Can you provide an example of Java JDialog?
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DialogExample { private static JDialog d; DialogExample() { JFrame f= new JFrame(); d = new JDialog(f , "Dialog Example", true); d.setLayout( new FlowLayout() ); JButton b = ...
What is Java JPanel?
The JPanel is a simplest container class. It provides space in which an application can attach any other component. It inherits the JComponents class. It doesn't have title bar.
What is JPanel class declaration?
public class JPanel extends JComponent implements Accessible
Can you provide an example of Java JPanel?
import java.awt.*; import javax.swing.*; public class PanelExample { PanelExample() { JFrame f= new JFrame("Panel Example"); JPanel panel=new JPanel(); panel.setBounds(40,80,200,200); panel.setBackground(Color.gray); JButton b1=new JBut...
What is Java JFileChooser?
JFileChooser is a class that is present in the java Swing package. The java Swing package is essential for JavaTM Foundation Classes(JFC). JFileChooser contains many elements that assist in building a graphical user Interface in java. Java Swing gives components like buttons, panels, dialogs, etc. JFileChooser is a sim...
Can you provide an example of Constructors Present in Java JFileChooser Class?
1. JFileChooser(): Constructs a JFileChooser highlighting the client's default directory. Example program on JFileChooser() // program to demonstrate the JFileChooser() constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.swing...
What is JFileChooser():?
Constructs a JFileChooser highlighting the client's default directory. Example program on JFileChooser() // program to demonstrate the JFileChooser() constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.swing.filechooser.*; cla...
Can you provide an example ofJFileChooser(File currentDirectory):?
Constructs a JFileChooser involving the given File as the way. Example program on JFileChooser(File currentDirectory) // program to demonstrate the JFileChooser(File currentDirectory) constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; impor...
Can you provide an example of JFileChooser(File currentDirectory, FileSystemViewfsv):?
Constructs a JFileChooser utilizing the given current catalog and FileSystemView. Example program on JFileChooser(File currentDirectory, FileSystemViewfsv) // program to demonstrate the JFileChooser(File currentDirectory, FileSystemViewfsv) constructor // importing the required packages import java.io.*; ...
Can you provide an example of JFileChooser(FileSystemViewfsv):?
Constructs a JFileChooser utilizing the given FileSystemView. Example program on JFileChooser(FileSystemViewfsv) // program to demonstrate the JFileChooser(FileSystemViewfsv) constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.sw...
Can you provide an example of JFileChooser(String currentDirectoryPath):?
Constructs a JFileChooser utilizing the given way. Example program on JFileChooser(String currentDirectoryPath): // program to demonstrate the JFileChooser(String currentDirectoryPath) constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; impo...
Can you provide an example of JFileChooser(String currentDirectoryPath, FileSystemViewfsv):?
Constructs a JFileChooser utilizing the given current catalog way and FileSystemView. Example program on JFileChooser( String currentDirectoryPath, FileSystemViewfsv ): // program to demonstrate the JFileChooser( String currentDirectoryPath, FileSystemViewfsv ) constructor // importing the required packages ...
Can you provide an example of JFileChooser( File ):?
Example program on JFileChooser( File ) constructor: // program to demonstrate the JFileChooser( file ) constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.swing.filechooser.*; classHelloWorld { public static void main(Stri...
Can you provide an example of JFileChooser(File, FileSystemView):?
Example on JFileChooser( File, FileSystemView ) // program to demonstrate the JFileChooser( file, FileSystemView ) constructor // importing the required packages import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.swing.filechooser.*; classHelloWorld { public static voi...
What are the Advantages of JFileChooser()?
1.Statement of the JFileChooser() beyond the occasion audience additionally can be used within the occasion audience. 2.JFileChooser return esteem, which portrays regardless of whether the record has been picked. 3.Boundary given to the accompanying strategy for JFileChooser can confine clients effectively to choose ei...
Can you give me Methods in JFileChooser Class?
The JFileChooser class fundamentally gives three strategies that show the record chooser discoursed, as in the accompanying:
what is showOpenDialog(component owner ):?
1. showOpenDialog(component owner ): This technique opens an exchange box that contains an endorsement button, as such, "Open", that opens a document from the discourse. Syntax: intshowOpenDialog(component proprietor);
What is showSaveDialog( component owner ):?
2. showSaveDialog( component owner ): This strategy is utilized when the client needs to save the particular document that he/she is utilizing. This exchange box contains an endorsement button, as such, "Save", to save the document. Syntax: intshowSaveDialog(component proprietor);
What is showDialog(component owner, string):?
3. showDialog(component owner, string): This technique shows an exchange box with an endorsement button which is client characterized. Syntax: intshowDialog(component owner,string);
What is getSelectedFile(): ?
4. getSelectedFile(): This technique returns the document that is chosen by the client. Syntax: filegetSelectedFile();
What is setCurrentDirectory(File f):?
5. setCurrentDirectory(File f): This technique sets the ongoing catalog as determined. Syntax: voidsetCurrentDirectory(File f);
What is getCurrentDirectory()?
6. getCurrentDirectory(): This technique for JFileChooser returns the ongoing index as chosen by the client. Syntax: filegetCurrentDirectory();
What is (File f)?
7. (File f):This strategy returns the name of the document as given by the record contention. Syntax: String getName(File f);
Can you provide an example of the program to create a JFrame window:?
A example program to create a JFrame window: // java program to create the frame and perform the action in that // importing the required packages and classes import java.io.*; importjavax.swing.*; importjava.awt.event.*; importjavax.swing.filechooser.*; classHelloWorld extends JFrame implements A...
What is Java JToggleButton?
JToggleButton is used to create toggle button, it is two-states button to switch on or off.
Can you provide an example of JToggleButton ?
import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JFrame; import javax.swing.JToggleButton; public class JToggleButtonExample extends JFrame implements ItemListener { public static void main(String[] args) { new JTogg...
What is Java JToolBar?
JToolBar container allows us to group other components, usually buttons with icons in a row or column. JToolBar provides a component which is useful for displaying commonly used actions or controls.
Can you provide an example of Java JToolBar?
import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JToolBar; public class JToolBarExample { public static void ma...
What is Java JViewport?
The JViewport class is used to implement scrolling. JViewport is designed to support both logical scrolling and pixel-based scrolling. The viewport's child, called the view, is scrolled by calling the JViewport.setViewPosition() method.
Can you provide an example of JViewport?
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.border.LineBorder; public class ViewPortClass2 { public static void main(Str...
What is Java JFrame?
The javax.swing.JFrame class is a type of container which inherits the java.awt.Frame class. JFrame works like the main window where components like labels, buttons, textfields are added to create a GUI. Unlike Frame, JFrame has the option to hide or close the window with the help of setDefaultCloseOperation(int) me...
Can you provide an example of JFrame?
import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class JFrameExample { public static void main(String s[]) { JFrame frame = new JFrame("JFrame Example"); JPanel panel = new JPanel()...
What is Java JComponent?
The JComponent class is the base class of all Swing components except top-level containers. Swing components whose names begin with "J" are descendants of the JComponent class. For example, JButton, JScrollPane, JPanel, JTable etc. But, JFrame and JDialog don't inherit JComponent class because they are the child of top...
Can you provide an example of Java JComponent?
import java.awt.Color; import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JFrame; class MyJComponent extends JComponent { public void paint(Graphics g) { g.setColor(Color.green); g.fillRect(30, 30, 100, 100); } } public class JComponentE...
What is Java JLayeredPane?
The JLayeredPane class is used to add depth to swing container. It is used to provide a third dimension for positioning component and divide the depth-range into several different layers.
What is JLayeredPane class declaration?
public class JLayeredPane extends JComponent implements Accessible
Can you provide an example of Java JLayeredPane?
import javax.swing.*; import java.awt.*; public class LayeredPaneExample extends JFrame { public LayeredPaneExample() { super("LayeredPane Example"); setSize(200, 200); JLayeredPane pane = getLayeredPane(); //creating buttons JButton top = new JButton(); top.setBackg...
What is Java JDesktopPane?
The JDesktopPane class, can be used to create "multi-document" applications. A multi-document application can have many windows included in it. We do it by making the contentPane in the main window as an instance of the JDesktopPane class or a subclass. Internal windows add instances of JInternalFrame to the JdesktopPa...
Can you provide an example of Java JDesktopPane?
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 JDPaneDemo extends JFrame { public JDPaneDemo() { CustomDesktopPane desktopPane = new Cus...
What is Java JEditorPane?
JEditorPane class is used to create a simple text editor window. This class has setContentType() and setText() methods.
What is setContentType("text/plain")?
setContentType("text/plain"): This method is used to set the content type to be plain text.
What is setText(text)?
setText(text): This method is used to set the initial text content.
Can you provide an example of JEditorPane?
import javax.swing.JEditorPane; import javax.swing.JFrame; public class JEditorPaneExample { JFrame myFrame = null; public static void main(String[] a) { (new JEditorPaneExample()).test(); } private void test() { myFrame = new JFrame("JEditorPane Test"...
What is Java JScrollPane?
A JscrollPane is used to make scrollable view of a component. When screen size is limited, we use a scroll pane to display a large component or a component whose size can change dynamically.
Can you provide an example of JScrollPane?
import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JtextArea; public class JScrollPaneExample { private static final long serialVersionUID = 1L; private static void createAndShowGUI() { // Create and set up the windo...
What is Java JSplitPane?
JSplitPane is used to divide two components. The two components are divided based on the look and feel implementation, and they can be resized by the user. If the minimum size of the two components is greater than the size of the split pane, the divider will not allow you to resize it. The two components in a split ...
Can you provide an example of JSplitPane?
import java.awt.FlowLayout; import java.awt.Panel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JSplitPane; public class JSplitPaneExample { private static void createAndShow() { // Create and set up the window. final JFrame frame = new JFrame("...
What is Java JTextPane?
JTextPane is a subclass of JEditorPane class. JTextPane is used for styled document with embedded images and components. It is text component that can be marked up with attributes that are represented graphically. JTextPane uses a DefaultStyledDocument as its default model.
Can you provide an example of JTextPane?
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.SimpleAttributeSet; ...