[go: up one dir, main page]

0% found this document useful (0 votes)
53 views25 pages

Methodsunit II Aj

This document summarizes the key methods and functionality of the JColorChooser, JComboBox, JFileChooser, JInternalFrame, and JLabel classes in Java. It describes how to initialize each class with different parameters, and lists some common methods for configuring properties and behaviors like setting colors, adding/removing items, selecting files/directories, setting titles and closability of internal frames, and getting text and icon properties of labels.

Uploaded by

sagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views25 pages

Methodsunit II Aj

This document summarizes the key methods and functionality of the JColorChooser, JComboBox, JFileChooser, JInternalFrame, and JLabel classes in Java. It describes how to initialize each class with different parameters, and lists some common methods for configuring properties and behaviors like setting colors, adding/removing items, selecting files/directories, setting titles and closability of internal frames, and getting text and icon properties of labels.

Uploaded by

sagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 25

JColorChooser()

Creates a color chooser pane with an initial color of white.


JColorChooser(Color initialColor)
Creates a color chooser pane with the specified initial color.
Color getColor()
Gets the current color value from the color chooser.
Methods
void setColor(Color color)
Sets the current color of the color chooser to the specified color.
void setColor(int c)
Sets the current color of the color chooser to the specified color.
void setColor(int r, int g, int b)
Sets the current color of the color chooser to the specified RGB color.
static Color showDialog(Component component, String title, Color initialColor)
Shows a modal color-chooser dialog and blocks until the dialog is hidden.
JComboBox()
Creates a JComboBox with a default data model.
JComboBox(ComboBoxModel<E> aModel)
Creates a JComboBox that takes its items from an existing ComboBoxModel.
JComboBox(E[] items)
Creates a JComboBox that contains the elements in the specified array.
JComboBox(Vector<E> items)
Creates a JComboBox that contains the elements in the specified Vector.
Methods
void addItem(E item)
Adds an item to the item list.
E getItemAt(int index)
Returns the list item at the specified index.
int getItemCount()
Returns the number of items in the list.
int getMaximumRowCount()
Returns the maximum number of items the combo box can display without a scrollbar
int getSelectedIndex()
Returns the first item in the list that matches the given item.
Object getSelectedItem()
Returns the current selected item.
Object[] getSelectedObjects()
Returns an array containing the selected item.
void insertItemAt(E item, int index)
Inserts an item into the item list at a given index.
boolean isEditable()
Returns true if the JComboBox is editable.
void removeAllItems()
Removes all items from the item list.
void removeItem(Object anObject)
Removes an item from the item list.
void removeItemAt(int anIndex)
Removes the item at anIndex This method works only if the JComboBox uses a
mutable data model.

void setEditable(boolean aFlag)


Determines whether the JComboBox field is editable.
void setEnabled(boolean b)
Enables the combo box so that items can be selected.
void setMaximumRowCount(int count)
Sets the maximum number of rows the JComboBox displays.
void setSelectedIndex(int anIndex)
Selects the item at index anIndex.
void setSelectedItem(Object anObject)
Sets the selected item in the combo box display area to the object in the argument.
void showPopup()
Causes the combo box to display its popup window.
void hidePopup()
Causes the combo box to close its popup window.

JFileChooser()
Constructs a JFileChooser pointing to the user's default directory.
JFileChooser(File currentDirectory)
Constructs a JFileChooser using the given File as the path.
JFileChooser(File currentDirectory, FileSystemView fsv)
Constructs a JFileChooser using the given current directory and FileSystemView.
JFileChooser(FileSystemView fsv)
Constructs a JFileChooser using the given FileSystemView.
JFileChooser(String currentDirectoryPath)
Constructs a JFileChooser using the given path.
JFileChooser(String currentDirectoryPath, FileSystemView fsv)
Constructs a JFileChooser using the given current directory path and FileSystemView.
Methods:
boolean accept(File f)
Returns true if the file should be displayed.
File getCurrentDirectory()
Returns the current directory.
String getDescription(File f)
Returns the file description.
int getFileSelectionMode()
Returns the current file-selection mode.
getIcon(File f)
Returns the icon for this file or type of file, depending on the system.
String getName(File f)
Returns the filename.
File getSelectedFile()
Returns the selected file.
File[] getSelectedFiles()
Returns a list of selected files if the file chooser is set to allow multiple selection.
String getTypeDescription(File f)
Returns the file type.
void setCurrentDirectory(File dir)
Sets the current directory.
void setDialogTitle(String dialogTitle)
Sets the string that goes in the JFileChooser window's title bar.

void setDialogType(int dialogType)


Sets the type of this dialog.
void setFileSelectionMode(int mode)
Sets the JFileChooser to allow the user to just select files, just select directories, or
select both files and directories.
void setMultiSelectionEnabled(boolean b)
Sets the file chooser to allow multiple file selections.
void setSelectedFile(File file)
Sets the selected file.
void setSelectedFiles(File[] selectedFiles)
Sets the list of selected files if the file chooser is set to allow multiple selection.
boolean isAcceptAllFileFilterUsed()
Returns whether the AcceptAll FileFilter is used.
boolean isDirectorySelectionEnabled()
Convenience call that determines if directories are selectable based on the current file
selection mode.
boolean isFileHidingEnabled()
Returns true if hidden files are not shown in the file chooser; otherwise, returns false.
boolean isFileSelectionEnabled()
Convenience call that determines if files are selectable based on the current file
selection mode.
boolean isMultiSelectionEnabled()
Returns true if multiple files can be selected.

JInternalFrame()
Creates a non-resizable, non-closable, non-maximizable, non-iconifiable JInternalFrame
with no title.
JInternalFrame(String title)
Creates a non-resizable, non-closable, non-maximizable, non-iconifiable JInternalFrame
with the specified title.
JInternalFrame(String title, boolean resizable)
Creates a non-closable, non-maximizable, non-iconifiable JInternalFrame with the
specified title and resizability.
JInternalFrame(String title, boolean resizable, boolean closable)
Creates a non-maximizable, non-iconifiable JInternalFrame with the specified title,
resizability, and closability.
JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable)
Creates a non-iconifiable JInternalFrame with the specified title, resizability, closability,
and maximizability.
JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable,
boolean iconifiable)
Creates a JInternalFrame with the specified title, resizability, closability, maximizability,
and iconifiability.
Methods
Container getContentPane()
Returns the content pane for this internal frame.
int getDefaultCloseOperation()

Returns the default operation that occurs when the user initiates a "close" on this
internal frame.
JInternalFrame.JDesktopIcon getDesktopIcon()
Returns the JDesktopIcon used when this JInternalFrame is iconified.
JDesktopPane getDesktopPane()
Convenience method that searches the ancestor hierarchy for a JDesktop instance.
Icon getFrameIcon()
Returns the image displayed in the title bar of this internal frame (usually in the top-left
corner).
String getTitle()
Returns the title of the JInternalFrame.
boolean isClosable()
Returns whether this JInternalFrame can be closed by some user action.
boolean isClosed()
Returns whether this JInternalFrame is currently closed.
boolean isFocusCycleRoot()
Always returns true because all JInternalFrames must be roots of a focus traversal
cycle.
boolean isIcon()
Returns whether the JInternalFrame is currently iconified.
boolean isIconifiable()
Gets the iconable property, which by default is false.
boolean isMaximizable()
Gets the value of the maximizable property.
boolean isMaximum()
Returns whether the JInternalFrame is currently maximized.
boolean isResizable()
Returns whether the JInternalFrame can be resized by some user action.
protected boolean isRootPaneCheckingEnabled()
Returns whether calls to add and setLayout are forwarded to the contentPane.
boolean isSelected()
Returns whether the JInternalFrame is the currently "selected" or active frame.
void reshape(int x, int y, int width, int height)
Moves and resizes this component.
void setClosable(boolean b)
Sets whether this JInternalFrame can be closed by some user action.
void setClosed(boolean b)
Closes this internal frame if the argument is true.
void setContentPane(Container c)
Sets this JInternalFrame's contentPane property.
void setDesktopIcon(JInternalFrame.JDesktopIcon d)
Sets the JDesktopIcon associated with this JInternalFrame.
void setFrameIcon(Icon icon)
Sets an image to be displayed in the titlebar of this internal frame (usually in the top-left
corner).
void setIcon(boolean b)
Iconifies or de-iconifies this internal frame, if the look and feel supports iconification.
void setIconifiable(boolean b)
Sets the iconable property, which must be true for the user to be able to make the
JInternalFrame an icon.
void setJMenuBar(JMenuBar m)

Sets the menuBar property for this JInternalFrame.


void setMaximizable(boolean b)
Sets the maximizable property, which determines whether the JInternalFrame can be
maximized by some user action.
void setMaximum(boolean b)
Maximizes and restores this internal frame.
void setSelected(boolean selected)
Selects or deselects the internal frame if it's showing.
void setTitle(String title)
Sets the JInternalFrame title.
void show()
If the internal frame is not visible, brings the internal frame to the front, makes it visible,
and attempts to select it.
JLabel()
Creates a JLabel instance with no image and with an empty string for the title.
JLabel(Icon image)
Creates a JLabel instance with the specified image.
JLabel(Icon image, int horizontalAlignment)
Creates a JLabel instance with the specified image and horizontal alignment.
JLabel(String text)
Creates a JLabel instance with the specified text.
JLabel(String text, Icon icon, int horizontalAlignment)
Creates a JLabel instance with the specified text, image, and horizontal alignment.
JLabel(String text, int horizontalAlignment)
Creates a JLabel instance with the specified text and horizontal alignment.
Methods
int getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.
int getHorizontalTextPosition()
Returns the horizontal position of the label's text, relative to its image.
Icon getIcon()
Returns the graphic image (glyph, icon) that the label displays.
String getText()
Returns the text string that the label displays.
int getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.
int getVerticalTextPosition()
Returns the vertical position of the label's text, relative to its image.
void setHorizontalAlignment(int alignment)
Sets the alignment of the label's contents along the X axis.
void setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the label's text, relative to its image.
void setIcon(Icon icon)
Defines the icon this component will display.
void setText(String text)
Defines the single line of text this component will display.
void setLabelFor(Component c)
Set the component this is labelling.
Component getLabelFor()
Get the component this is labelling.

JMenuBar()
Creates a new menu bar.
Methods
JMenu add(JMenu c)
Appends the specified menu to the end of the menu bar.
JMenu getMenu(int index)
Returns the menu at the specified position in the menu bar.
int getMenuCount()
Returns the number of items in the menu bar.
boolean isBorderPainted()
Returns true if the menu bars border should be painted.
boolean isSelected()
Returns true if the menu bar currently has a component selected.
protected void paintBorder(Graphics g)
Paints the menubar's border if BorderPainted property is true.
void setBorderPainted(boolean b)
Sets whether the border should be painted.
void setSelected(Component sel)
Sets the currently selected component, producing a a change to the selection model.
JOptionPane()
Creates a JOptionPane with a test message.
JOptionPane(Object message)
Creates a instance of JOptionPane to display a message using the plain-message
message type and the default options delivered by the UI.
JOptionPane(Object message, int messageType)
Creates an instance of JOptionPane to display a message with the specified message
type and the default options,
JOptionPane(Object message, int messageType, int optionType)
Creates an instance of JOptionPane to display a message with the specified message
type and options.
JOptionPane(Object message, int messageType, int optionType, Icon icon)
Creates an instance of JOptionPane to display a message with the specified message
type, options, and icon.
JOptionPane(Object message, int messageType, int optionType, Icon icon,
Object[] options)
Creates an instance of JOptionPane to display a message with the specified message
type, icon, and options.
JOptionPane(Object message, int messageType, int optionType, Icon icon,
Object[] options, Object initialValue)
Creates an instance of JOptionPane to display a message with the specified message
type, icon, and options, with the initially-selected option specified.
Methods
Icon getIcon()
Returns the icon this pane displays.
Object getInitialSelectionValue()
Returns the input value that is displayed as initially selected to the user.
Object getInitialValue()
Returns the initial value.
Object getInputValue()
Returns the value the user has input, if wantsInput is true.

int getMaxCharactersPerLineCount()
Returns the maximum number of characters to place on a line in a message.
Object getMessage()
Returns the message-object this pane displays.
int getMessageType()
Returns the message type.
Object[] getOptions()
Returns the choices the user can make.
int getOptionType()
Returns the type of options that are displayed.
Object getValue()
Returns the value the user has selected.
void selectInitialValue()
Requests that the initial value be selected, which will set focus to the initial value.
void setIcon(Icon newIcon)
Sets the icon to display.
void setInitialSelectionValue(Object newValue)
Sets the input value that is initially displayed as selected to the user.
void setInitialValue(Object newInitialValue)
Sets the initial value that is to be enabled -- the Component that has the focus when the
pane is initially displayed.
void setInputValue(Object newValue)
Sets the input value that was selected or input by the user.
void setMessage(Object newMessage)
Sets the option pane's message-object.
void setMessageType(int newType)
Sets the option pane's message type.
void setOptions(Object[] newOptions)
Sets the options this pane displays.
void setOptionType(int newType)
Sets the options to display.
void setSelectionValues(Object[] newValues)
Sets the input selection values for a pane that provides the user with a list of items to
choose from.
static int showConfirmDialog(Component parentComponent, Object message)
Brings up a dialog with the options Yes, No and Cancel; with the title, Select an Option.
static int showConfirmDialog(Component parentComponent, Object message,
String title, int optionType)
Brings up a dialog where the number of choices is determined by the optionType
parameter.
static int showConfirmDialog(Component parentComponent, Object message,
String title, int optionType, int messageType)
Brings up a dialog where the number of choices is determined by the optionType
parameter, where the messageType parameter determines the icon to display.
static int showConfirmDialog(Component parentComponent, Object message,
String title, int optionType, int messageType, Icon icon)
Brings up a dialog with a specified icon, where the number of choices is determined by
the optionType parameter.
static String showInputDialog(Component parentComponent, Object message)
Shows a question-message dialog requesting input from the user parented to
parentComponent.

static String showInputDialog(Component parentComponent, Object message,


Object initialSelectionValue)
Shows a question-message dialog requesting input from the user and parented to
parentComponent.
static String showInputDialog(Component parentComponent, Object message,
String title, int messageType)
Shows a dialog requesting input from the user parented to parentComponent with the
dialog having the title title and message type messageType.
static Object showInputDialog(Component parentComponent, Object message,
String title, int messageType, Icon icon, Object[] selectionValues,
Object initialSelectionValue)
Prompts the user for input in a blocking dialog where the initial selection, possible
selections, and all other options can be specified.
static String showInputDialog(Object message)
Shows a question-message dialog requesting input from the user.
static void showMessageDialog(Component parentComponent, Object message)
Brings up an information-message dialog titled "Message".
static void showMessageDialog(Component parentComponent, Object message,
String title, int messageType)
Brings up a dialog that displays a message using a default icon determined by the
messageType parameter.
static void showMessageDialog(Component parentComponent, Object message,
String title, int messageType, Icon icon)
Brings up a dialog displaying a message, specifying all parameters.
static int showOptionDialog(Component parentComponent, Object message,
String title, int optionType, int messageType, Icon icon, Object[] options,
Object initialValue)
Brings up a dialog with a specified icon, where the initial choice is determined by the
initialValue parameter and the number of choices is determined by the optionType
parameter.
JLayeredPane()
Create a new JLayeredPane
Methods
int getComponentCountInLayer(int layer)
Returns the number of children currently in the specified layer.
Component[] getComponentsInLayer(int layer)
Returns an array of the components in the specified layer.
int getLayer(Component c)
Returns the layer attribute for the specified Component.
static int getLayer(JComponent c)
Gets the layer property for a JComponent, it does not cause any side effects like
setLayer().
int getPosition(Component c)
Get the relative position of the component within its layer.
int highestLayer()
Returns the highest layer value from all current children.
protected int insertIndexForLayer(int layer, int position)
Primitive method that determines the proper location to insert a new child based on
layer and position requests.
int lowestLayer()
Returns the lowest layer value from all current children.

void moveToBack(Component c)
Moves the component to the bottom of the components in its current layer (position -1).
void moveToFront(Component c)
Moves the component to the top of the components in its current layer (position 0).
void paint(Graphics g)
Paints this JLayeredPane within the specified graphics context.
void remove(int index)
Remove the indexed component from this pane.
void removeAll()
Removes all the components from this container.
void setLayer(Component c, int layer)
Sets the layer attribute on the specified component, making it the bottommost
component in that layer.
void setLayer(Component c, int layer, int position)
Sets the layer attribute for the specified component and also sets its position within that
layer.
void setPosition(Component c, int position)
Moves the component to position within its current layer, where 0 is the topmost position
within the layer and -1 is the bottommost position.
JDesktopPane()
Creates a new JDesktopPane.
Methods:
JInternalFrame[] getAllFrames()
Returns all JInternalFrames currently displayed in the desktop.
JInternalFrame[] getAllFramesInLayer(int layer)
Returns all JInternalFrames currently displayed in the specified layer of the desktop.
int getDragMode()
Gets the current "dragging style" used by the desktop pane.
JInternalFrame getSelectedFrame()
Returns the currently active JInternalFrame in this JDesktopPane, or null if no
JInternalFrame is currently active.
void remove(int index)
Remove the indexed component from this pane.
void removeAll()
Removes all the components from this container.
JInternalFrame selectFrame(boolean forward)
Selects the next JInternalFrame in this desktop pane.
void setDragMode(int dragMode)
Sets the "dragging style" used by the desktop pane.
void setSelectedFrame(JInternalFrame f)
Sets the currently active JInternalFrame in this JDesktopPane.
JPanel()
Creates a new JPanel with a double buffer and a flow layout.
JPanel(LayoutManager layout)
Create a new buffered JPanel with the specified layout manager
Methods:
JPopupMenu()
Constructs a JPopupMenu without an "invoker".
JPopupMenu(String label)
Constructs a JPopupMenu with the specified title.

Methods:
JMenuItem add(JMenuItem menuItem)
Appends the specified menu item to the end of this menu.
JMenuItem add(String s)
Creates a new menu item with the specified text and appends it to the end of this menu.
void addSeparator()
Appends a new separator at the end of the menu.
Component getComponent()
Returns this JPopupMenu component.
int getComponentIndex(Component c)
Returns the index of the specified component.
String getLabel()
Returns the popup menu's label
void insert(Action a, int index)
Inserts a menu item for the specified Action object at a given position.
void insert(Component component, int index)
Inserts the specified component into the menu at a given position.
boolean isBorderPainted()
Checks whether the border should be painted.
boolean isVisible()
Returns true if the popup menu is visible (currently being displayed).
void remove(int pos)
Removes the component at the specified index from this popup menu.
void setBorderPainted(boolean b)
Sets whether the border should be painted.
void setLabel(String label)
Sets the popup menu's label.
void setLocation(int x, int y)
Sets the location of the upper left corner of the popup menu using x, y coordinates.
void setPopupSize(Dimension d)
Sets the size of the Popup window using a Dimension object.
void setPopupSize(int width, int height)
Sets the size of the Popup window to the specified width and height.
void setSelected(Component sel)
Sets the currently selected component, This will result in a change to the selection
model.
void setVisible(boolean b)
Sets the visibility of the popup menu.
void show(Component invoker, int x, int y)
Displays the popup menu at the position x,y in the coordinate space of the component
invoker.
JProgressBar()
Creates a horizontal progress bar that displays a border but no progress string.
JProgressBar(int orient)
Creates a progress bar with the specified orientation, which can be either
SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
JProgressBar(int min, int max)
Creates a horizontal progress bar with the specified minimum and maximum.
JProgressBar(int orient, int min, int max)
Creates a progress bar using the specified orientation, minimum, and maximum.

Methods:
int getMaximum()
Returns the progress bar's maximum value from the BoundedRangeModel.
int getMinimum()
Returns the progress bar's minimum value from the BoundedRangeModel.
int getOrientation()
Returns SwingConstants.VERTICAL or SwingConstants.HORIZONTAL, depending on
the orientation of the progress bar.
String getString()
Returns a String representation of the current progress.
int getValue()
Returns the progress bar's current value from the BoundedRangeModel.
boolean isBorderPainted()
Returns the borderPainted property.
boolean isStringPainted()
Returns the value of the stringPainted property.
void setBorderPainted(boolean b)
Sets the borderPainted property, which is true if the progress bar should paint its border.
void setMaximum(int n)
Sets the progress bar's maximum value (stored in the progress bar's data model) to n.
void setMinimum(int n)
Sets the progress bar's minimum value (stored in the progress bar's data model) to n.
void setOrientation(int newOrientation)
Sets the progress bar's orientation to newOrientation, which must be
SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
void setString(String s)
Sets the value of the progress string.
void setValue(int n)
Sets the progress bar's current value to n.
JRootPane()
Creates a JRootPane, setting up its glassPane, layeredPane, and contentPane.
Methods:
Container getContentPane()
Returns the content pane -- the container that holds the components parented by the
root pane.
JButton getDefaultButton()
Returns the value of the defaultButton property.
protected Container createContentPane()
Called by the constructor methods to create the default contentPane.
protected Component createGlassPane()
Called by the constructor methods to create the default glassPane.
protected JLayeredPane createLayeredPane()
Called by the constructor methods to create the default layeredPane.
protected LayoutManager createRootLayout()
Called by the constructor methods to create the default layoutManager.
Container getContentPane()
Returns the content pane -- the container that holds the components parented by the
root pane.
JButton getDefaultButton()
Returns the value of the defaultButton property.

Component getGlassPane()
Returns the current glass pane for this JRootPane.
JMenuBar getJMenuBar()
Returns the menu bar from the layered pane.
JLayeredPane getLayeredPane()
Gets the layered pane used by the root pane.
void setContentPane(Container content)
Sets the content pane -- the container that holds the components parented by the root
pane.
void setDefaultButton(JButton defaultButton)
Sets the defaultButton property, which determines the current default button for this
JRootPane.
void setDoubleBuffered(boolean aFlag)
Sets whether this component should use a buffer to paint.
void setGlassPane(Component glass)
Sets a specified Component to be the glass pane for this root pane.
void setJMenuBar(JMenuBar menu)
Adds or changes the menu bar used in the layered pane.
void setLayeredPane(JLayeredPane layered)
Sets the layered pane for the root pane.
JScrollBar()
Creates a vertical scrollbar with the following initial values:
JScrollBar(int orientation)
Creates a scrollbar with the specified orientation and the following initial values:
JScrollBar(int orientation, int value, int extent, int min, int max)
Creates a scrollbar with the specified orientation, value, extent, minimum, and
maximum.
Methods:
int getMaximum()
The maximum value of the scrollbar is maximum - extent.
Dimension getMaximumSize()
The scrollbar is flexible along it's scrolling axis and rigid along the other axis.
int getMinimum()
Returns the minimum value supported by the scrollbar (usually zero).
Dimension getMinimumSize()
The scrollbar is flexible along it's scrolling axis and rigid along the other axis.
int getOrientation()
Returns the component's orientation (horizontal or vertical).
int getUnitIncrement()
For backwards compatibility with java.awt.Scrollbar.
int getUnitIncrement(int direction)
Returns the amount to change the scrollbar's value by, given a unit up/down request.
int getValue()
Returns the scrollbar's value.
boolean getValueIsAdjusting()
True if the scrollbar knob is being dragged.
int getVisibleAmount()
Returns the scrollbar's extent, aka its "visibleAmount".
void setBlockIncrement(int blockIncrement)
Sets the blockIncrement property.
void setEnabled(boolean x)

Enables the component so that the knob position can be changed.


void setMaximum(int maximum)
Sets the model's maximum property.
void setMinimum(int minimum)
Sets the model's minimum property.
void setOrientation(int orientation)
Set the scrollbar's orientation to either VERTICAL or HORIZONTAL.
void setUnitIncrement(int unitIncrement)
Sets the unitIncrement property.
void setValue(int value)
Sets the scrollbar's value.
void setValueIsAdjusting(boolean b)
Sets the model's valueIsAdjusting property.
void setValues(int newValue, int newExtent, int newMin, int newMax)
Sets the four BoundedRangeModel properties after forcing the arguments to obey the
usual constraints:
void setVisibleAmount(int extent)
Set the model's extent property.
JScrollPane()
Creates an empty (no viewport view) JScrollPane where both horizontal and vertical
scrollbars appear when needed.
JScrollPane(Component view)
Creates a JScrollPane that displays the contents of the specified component, where
both horizontal and vertical scrollbars appear whenever the component's contents are
larger than the view.
JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
Creates a JScrollPane that displays the view component in a viewport whose view
position can be controlled with a pair of scrollbars.
JScrollPane(int vsbPolicy, int hsbPolicy)
Creates an empty (no viewport view) JScrollPane with specified scrollbar policies.
JScrollBar createHorizontalScrollBar()
Returns a JScrollPane.ScrollBar by default.
JScrollBar createVerticalScrollBar()
Returns a JScrollPane.ScrollBar by default.
JScrollBar getHorizontalScrollBar()
Returns the horizontal scroll bar that controls the viewport's horizontal view position.
JScrollBar getVerticalScrollBar()
Returns the vertical scroll bar that controls the viewports vertical view position.
void setComponentOrientation(ComponentOrientation co)
Sets the orientation for the vertical and horizontal scrollbars as determined by the
ComponentOrientation argument.
void setHorizontalScrollBar(JScrollBar horizontalScrollBar)
Adds the scrollbar that controls the viewport's horizontal view position to the scrollpane.
void setVerticalScrollBar(JScrollBar verticalScrollBar)
Adds the scrollbar that controls the viewports vertical view position to the scrollpane.
JSeparator()
Creates a new horizontal separator.
JSeparator(int orientation)
Creates a new separator with the specified horizontal or vertical orientation.
Methods:
int getOrientation()

Returns the orientation of this separator.


void setOrientation(int orientation)
Sets the orientation of the separator.
JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial value of 50.
JSlider(int orientation)
Creates a slider using the specified orientation with the range 0 to 100 and an initial
value of 50.
JSlider(int min, int max)
Creates a horizontal slider using the specified min and max with an initial value equal to
the average of the min plus max.
JSlider(int min, int max, int value)
Creates a horizontal slider using the specified min, max and value.
JSlider(int orientation, int min, int max, int value)
Creates a slider with the specified orientation and the specified minimum, maximum,
and initial values.
Methods:
int getMaximum()
Returns the maximum value supported by the slider from the BoundedRangeModel.
int getMinimum()
Returns the minimum value supported by the slider from the BoundedRangeModel.
int getOrientation()
Return this slider's vertical or horizontal orientation.
boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
Repaints the component when the image has changed.
void setFont(Font font)
Sets the font for this component.
void setMaximum(int maximum)
Sets the slider's maximum value to maximum.
void setMinimum(int minimum)
Sets the slider's minimum value to minimum.
JSplitPane()
Creates a new JSplitPane configured to arrange the child components side-by-side
horizontally, using two buttons for the components.
JSplitPane(int newOrientation)
Creates a new JSplitPane configured with the specified orientation.
JSplitPane(int newOrientation, boolean newContinuousLayout)
Creates a new JSplitPane with the specified orientation and redrawing style.
JSplitPane(int newOrientation, boolean newContinuousLayout,
Component newLeftComponent, Component newRightComponent)
Creates a new JSplitPane with the specified orientation and redrawing style, and with
the specified components.
JSplitPane(int newOrientation, Component newLeftComponent,
Component newRightComponent)
Creates a new JSplitPane with the specified orientation and the specified components.
Methods:
Component getBottomComponent()
Returns the component below, or to the right of the divider.
int getOrientation()
Returns the orientation.

Component getRightComponent()
Returns the component to the right (or below) the divider.
Component getTopComponent()
Returns the component above, or to the left of the divider.
void remove(Component component)
Removes the child component, component from the pane.
void remove(int index)
Removes the Component at the specified index.
void removeAll()
Removes all the child components from the split pane.
void setBottomComponent(Component comp)
Sets the component below, or to the right of the divider.
void setLeftComponent(Component comp)
Sets the component to the left (or above) the divider.
void setOrientation(int orientation)
Sets the orientation, or how the splitter is divided.
void setTopComponent(Component comp)
Sets the component above, or to the left of the divider.
JTabbedPane()
Creates an empty TabbedPane with a default tab placement of JTabbedPane.TOP.
JTabbedPane(int tabPlacement)
Creates an empty TabbedPane with the specified tab placement of either:
JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane.LEFT, or
JTabbedPane.RIGHT.
JTabbedPane(int tabPlacement, int tabLayoutPolicy)
Creates an empty TabbedPane with the specified tab placement and tab layout policy.
Methods:
Component add(Component component)
Adds a component with a tab title defaulting to the name of the component which is the
result of calling component.getName.
Component add(Component component, int index)
Adds a component at the specified tab index with a tab title defaulting to the name of
the component.
void add(Component component, Object constraints)
Adds a component to the tabbed pane.
void add(Component component, Object constraints, int index)
Adds a component at the specified tab index.
Component add(String title, Component component)
Adds a component with the specified tab title.
void addTab(String title, Component component)
Adds a component represented by a title and no icon.
void addTab(String title, Icon icon, Component component)
Adds a component represented by a title and/or icon, either of which can be null.
void addTab(String title, Icon icon, Component component, String tip)
Adds a component and tip represented by a title and/or icon, either of which can be null.
Color getBackgroundAt(int index)
Returns the tab background color at index.
Component getComponentAt(int index)
Returns the component at index.
Icon getIconAt(int index)
Returns the tab icon at index.

int getSelectedIndex()
Returns the currently selected index for this tabbedpane.
Component getTabComponentAt(int index)
Returns the tab component at index.
int getTabCount()
Returns the number of tabs in this tabbedpane.
String getTitleAt(int index)
Returns the tab title at index.
String getToolTipText(MouseEvent event)
Returns the tooltip text for the component determined by the mouse event location.
String getToolTipTextAt(int index)
Returns the tab tooltip text at index.
void insertTab(String title, Icon icon, Component component, String tip, int index)
Inserts a new tab for the given component, at the given index, represented by the given
title and/or icon, either of which may be null.
boolean isEnabledAt(int index)
Returns whether or not the tab at index is currently enabled.
void remove(Component component)
Removes the specified Component from the JTabbedPane.
void remove(int index)
Removes the tab and component which corresponds to the specified index.
void removeAll()
Removes all the tabs and their corresponding components from the tabbedpane.
void setBackgroundAt(int index, Color background)
Sets the background color at index to background which can be null, in which case the
tab's background color will default to the background color of the tabbedpane.
void setComponentAt(int index, Component component)
Sets the component at index to component.
void setEnabledAt(int index, boolean enabled)
Sets whether or not the tab at index is enabled.
void setForegroundAt(int index, Color foreground)
Sets the foreground color at index to foreground which can be null, in which case the
tab's foreground color will default to the foreground color of this tabbedpane.
void setIconAt(int index, Icon icon)
Sets the icon at index to icon which can be null.
void setSelectedComponent(Component c)
Sets the selected component for this tabbedpane.
void setSelectedIndex(int index)
Sets the selected index for this tabbedpane.
void setTabComponentAt(int index, Component component)
Sets the component that is responsible for rendering the title for the specified tab.
void setTitleAt(int index, String title)
Sets the title at index to title which can be null.
void setToolTipTextAt(int index, String toolTipText)
Sets the tooltip text at index to toolTipText which can be null.
JTable()
Constructs a default JTable that is initialized with a default data model, a default column
model, and a default selection model.
JTable(int numRows, int numColumns)
Constructs a JTable with numRows and numColumns of empty cells using
DefaultTableModel.

JTable(Object[][] rowData, Object[] columnNames)


Constructs a JTable to display the values in the two dimensional array, rowData, with
column names, columnNames.
JTable(TableModel dm)
Constructs a JTable that is initialized with dm as the data model, a default column
model, and a default selection model.
JTable(TableModel dm, TableColumnModel cm)
Constructs a JTable that is initialized with dm as the data model, cm as the column
model, and a default selection model.
JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
Constructs a JTable that is initialized with dm as the data model, cm as the column
model, and sm as the selection model.
JTable(Vector rowData, Vector columnNames)
Constructs a JTable to display the values in the Vector of Vectors, rowData, with column
names, columnNames.
Methods:
void addColumn(TableColumn aColumn)
Appends aColumn to the end of the array of columns held by this JTable's column
model.
void clearSelection()
Deselects all selected columns and rows.
boolean editCellAt(int row, int column)
Programmatically starts editing the cell at row and column, if those indices are in the
valid range, and the cell at those indices is editable.
Rectangle getCellRect(int row, int column, boolean includeSpacing)
Returns a rectangle for the cell that lies at the intersection of row and column.
TableColumn getColumn(Object identifier)
Returns the TableColumn object for the column in the table whose identifier is equal to
identifier, when compared using equals.
int getColumnCount()
Returns the number of columns in the column model.
String getColumnName(int column)
Returns the name of the column appearing in the view at column position column.
boolean getColumnSelectionAllowed()
Returns true if columns can be selected.
int getRowCount()
Returns the number of rows that can be shown in the JTable, given unlimited space.
int getRowHeight()
Returns the height of a table row, in pixels.
int getRowHeight(int row)
Returns the height, in pixels, of the cells in row.
int getRowMargin()
Gets the amount of empty space, in pixels, between cells.
boolean getRowSelectionAllowed()
Returns true if rows can be selected.
int getSelectedColumn()
Returns the index of the first selected column, -1 if no column is selected.
int getSelectedColumnCount()
Returns the number of selected columns.
int[] getSelectedColumns()

Returns the indices of all selected columns.


int getSelectedRow()
Returns the index of the first selected row, -1 if no row is selected.
int getSelectedRowCount()
Returns the number of selected rows.
int[] getSelectedRows()
Returns the indices of all selected rows.
Color getSelectionBackground()
Returns the background color for selected cells.
Color getSelectionForeground()
Returns the foreground color for selected cells.
Object getValueAt(int row, int column)
Returns the cell value at row and column.
boolean isCellEditable(int row, int column)
Returns true if the cell at row and column is editable.
boolean isCellSelected(int row, int column)
Returns true if the specified indices are in the valid range of rows and columns and the
cell at the specified position is selected.
boolean isColumnSelected(int column)
Returns true if the specified index is in the valid range of columns, and the column at
that index is selected.
boolean isEditing()
Returns true if a cell is being edited.
boolean isRowSelected(int row)
Returns true if the specified index is in the valid range of rows, and the row at that index
is selected.
void removeColumn(TableColumn aColumn)
Removes aColumn from this JTable's array of columns.
void selectAll()
Selects all rows, columns, and cells in the table.
void setRowHeight(int rowHeight)
Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints.
void setRowHeight(int row, int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints.
void setRowMargin(int rowMargin)
Sets the amount of empty space between cells in adjacent rows.
void setRowSelectionAllowed(boolean rowSelectionAllowed)
Sets whether the rows in this model can be selected.
void setSelectionBackground(Color selectionBackground)
Sets the background color for selected cells.
void setSelectionForeground(Color selectionForeground)
Sets the foreground color for selected cells.
void setSelectionMode(int selectionMode)
Sets the table's selection mode to allow only single selections, a single contiguous
interval, or multiple intervals.
void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
JTableHeader()
Constructs a JTableHeader with a default TableColumnModel.

JTableHeader(TableColumnModel cm)
Constructs a JTableHeader which is initialized with cm as the column model.
Methods:
JTable getTable()
Returns the table associated with this header.
void setTable(JTable table)
Sets the table associated with this header.
JToolBar()
Creates a new tool bar; orientation defaults to HORIZONTAL.
JToolBar(int orientation)
Creates a new tool bar with the specified orientation.
JToolBar(String name)
Creates a new tool bar with the specified name.
JToolBar(String name, int orientation)
Creates a new tool bar with a specified name and orientation.
Methods:
void addSeparator()
Appends a separator of default size to the end of the tool bar.
Component getComponentAtIndex(int i)
Returns the component at the specified index.
int getOrientation()
Returns the current orientation of the tool bar.
boolean isBorderPainted()
Gets the borderPainted property.
void setBorderPainted(boolean b)
Sets the borderPainted property, which is true if the border should be painted.
void setLayout(LayoutManager mgr)
Sets the layout manager for this container.
void setOrientation(int o)
Sets the orientation of the tool bar.
JToolTip()
Creates a tool tip.
Methods:
String getTipText()
Returns the text that is shown when the tool tip is displayed.
void setTipText(String tipText)
Sets the text to show when the tool tip is displayed.
JTree()
Refer corejav2
JViewport()
Creates a JViewport.
Mthods:
int getScrollMode()
Returns the current scrolling mode.
Component getView()
Returns the JViewport's one child or null.
Dimension getViewSize()
If the view's size hasn't been explicitly set, return the preferred size, otherwise return the
view's current size.
void remove(Component child)

Removes the Viewports one lightweight child.


void setBorder(Border border)
The viewport "scrolls" its child (called the "view") by the normal parent/child clipping
(typically the view is moved in the opposite direction of the scroll).
void setScrollMode(int mode)
Used to control the method of scrolling the viewport contents.
void setView(Component view)
Sets the JViewport's one lightweight child (view), which can be null.
void setViewPosition(Point p)
Sets the view coordinates that appear in the upper left hand corner of the viewport,
does nothing if there's no view.
JEditorPane
Refer corejava2
JTextPane()
Creates a new JTextPane.
Methods:
void insertComponent(Component c)
Inserts a component into the document as a replacement for the currently selected
content.
void insertIcon(Icon g)
Inserts an icon into the document as a replacement for the currently selected content.
void setDocument(Document doc)
Associates the editor with a text document.
void replaceSelection(String content)
Replaces the currently selected content with new content represented by the given
string.
JTextArea()
Constructs a new TextArea.
JTextArea(int rows, int columns)
Constructs a new empty TextArea with the specified number of rows and columns.
JTextArea(String text)
Constructs a new TextArea with the specified text displayed.
JTextArea(String text, int rows, int columns)
Constructs a new TextArea with the specified text and number of rows and columns.
Methods:
void append(String str)
Appends the given text to the end of the document.
int getColumns()
Returns the number of columns in the TextArea.
protected int getColumnWidth()
Gets column width.
int getLineCount()
Determines the number of lines contained in the area.
boolean getLineWrap()
Gets the line-wrapping policy of the text area.
protected int getRowHeight()
Defines the meaning of the height of a row.
int getRows()
Returns the number of rows in the TextArea.

boolean getWrapStyleWord()
Gets the style of wrapping used if the text area is wrapping lines.
void insert(String str, int pos)
Inserts the specified text at the specified position.
void setColumns(int columns)
Sets the number of columns for this TextArea.
void setFont(Font f)
Sets the current font.
void setLineWrap(boolean wrap)
Sets the line-wrapping policy of the text area.
void setRows(int rows)
Sets the number of rows for this TextArea.
void setTabSize(int size)
Sets the number of characters to expand tabs to.
void setWrapStyleWord(boolean word)
Sets the style of wrapping used if the text area is wrapping lines.
JTextField()
Constructs a new TextField.
JTextField(int columns)
Constructs a new empty TextField with the specified number of columns.
JTextField(String text)
Constructs a new TextField initialized with the specified text.
JTextField(String text, int columns)
Constructs a new TextField initialized with the specified text and columns.
Methods:
int getColumns()
Returns the number of columns in this TextField.
protected int getColumnWidth()
Returns the column width.
int getHorizontalAlignment()
Returns the horizontal alignment of the text.
void setColumns(int columns)
Sets the number of columns in this TextField, and then invalidate the layout.
void setFont(Font f)
Sets the current font.
void setHorizontalAlignment(int alignment)
Sets the horizontal alignment of the text.
JPasswordField()
Constructs a new JPasswordField, with a default document, null starting text string, and
0 column width.
JPasswordField(int columns)
Constructs a new empty JPasswordField with the specified number of columns.
JPasswordField(String text)
Constructs a new JPasswordField initialized with the specified text.
JPasswordField(String text, int columns)
Constructs a new JPasswordField initialized with the specified text and columns.
Methods:
void copy()
Invokes provideErrorFeedback on the current look and feel, which typically initiates an
error beep.
void cut()

Invokes provideErrorFeedback on the current look and feel, which typically initiates an
error beep.
boolean echoCharIsSet()
Returns true if this JPasswordField has a character set for echoing.
char getEchoChar()
Returns the character to be used for echoing.
char[] getPassword()
Returns the text contained in this TextComponent.
void setEchoChar(char c)
Sets the echo character for this JPasswordField.
JButton()
Creates a button with no set text or icon.
JButton(Icon icon)
Creates a button with an icon.
JButton(String text)
Creates a button with text.
JButton(String text, Icon icon)
Creates a button with initial text and an icon.
Methods:
boolean isDefaultButton()
Gets the value of the defaultButton property, which if true means that this button is the
current default button for its JRootPane.
JMenuItem()
Creates a JMenuItem with no set text or icon.
JMenuItem(Icon icon)
Creates a JMenuItem with the specified icon.
JMenuItem(String text)
Creates a JMenuItem with the specified text.
JMenuItem(String text, Icon icon)
Creates a JMenuItem with the specified text and icon.
JMenuItem(String text, int mnemonic)
Creates a JMenuItem with the specified text and keyboard mnemonic.
Methods:
void setEnabled(boolean b)
Enables or disables the menu item.
JCheckBoxMenuItem()
Creates an initially unselected check box menu item with no set text or icon.
JCheckBoxMenuItem(Icon icon)
Creates an initially unselected check box menu item with an icon.
JCheckBoxMenuItem(String text)
Creates an initially unselected check box menu item with text.
JCheckBoxMenuItem(String text, boolean b)
Creates a check box menu item with the specified text and selection state.
JCheckBoxMenuItem(String text, Icon icon)
Creates an initially unselected check box menu item with the specified text and icon.
JCheckBoxMenuItem(String text, Icon icon, boolean b)
Creates a check box menu item with the specified text, icon, and selection state.
Methods:
boolean getState()
Returns the selected-state of the item.

void setState(boolean b)
Sets the selected-state of the item.
JRadioButtonMenuItem()
Creates a JRadioButtonMenuItem with no set text or icon.
JRadioButtonMenuItem(Icon icon)
Creates a JRadioButtonMenuItem with an icon.
JRadioButtonMenuItem(Icon icon, boolean selected)
Creates a radio button menu item with the specified image and selection state, but no
text.
JRadioButtonMenuItem(String text)
Creates a JRadioButtonMenuItem with text.
JRadioButtonMenuItem(String text, boolean selected)
Creates a radio button menu item with the specified text and selection state.
JRadioButtonMenuItem(String text, Icon icon)
Creates a radio button menu item with the specified text and Icon.
JRadioButtonMenuItem(String text, Icon icon, boolean selected)
Creates a radio button menu item that has the specified text, image, and selection state.
JCheckBox()
Creates an initially unselected check box button with no text, no icon.
JCheckBox(Icon icon)
Creates an initially unselected check box with an icon.
JCheckBox(Icon icon, boolean selected)
Creates a check box with an icon and specifies whether or not it is initially selected.
JCheckBox(String text)
Creates an initially unselected check box with text.
JCheckBox(String text, boolean selected)
Creates a check box with text and specifies whether or not it is initially selected.
JCheckBox(String text, Icon icon)
Creates an initially unselected check box with the specified text and icon.
JCheckBox(String text, Icon icon, boolean selected)
Creates a check box with text and icon, and specifies whether or not it is initially
selected.
Method:
JRadioButton()
Creates an initially unselected radio button with no set text.
JRadioButton(Icon icon)
Creates an initially unselected radio button with the specified image but no text.
JRadioButton(Icon icon, boolean selected)
Creates a radio button with the specified image and selection state, but no text.
JRadioButton(String text)
Creates an unselected radio button with the specified text.
JRadioButton(String text, boolean selected)
Creates a radio button with the specified text and selection state.
JRadioButton(String text, Icon icon)
Creates a radio button that has the specified text and image, and that is initially
unselected.
JRadioButton(String text, Icon icon, boolean selected)
Creates a radio button that has the specified text, image, and selection state.
JMenu()

Constructs a new JMenu with no text.


JMenu(String s)
Constructs a new JMenu with the supplied string as its text.
JMenu(String s, boolean b)
Constructs a new JMenu with the supplied string as its text and specified as a tear-off
menu or not.
Method:
JMenuItem add(Action a)
Creates a new menu item attached to the specified Action object and appends it to the
end of this menu.
Component add(Component c)
Appends a component to the end of this menu.
Component add(Component c, int index)
Adds the specified component to this container at the given position.
JMenuItem add(JMenuItem menuItem)
Appends a menu item to the end of this menu.
JMenuItem add(String s)
Creates a new menu item with the specified text and appends it to the end of this menu.
Method:
void addSeparator()
Appends a new separator to the end of the menu.
JMenuItem getItem(int pos)
Returns the JMenuItem at the specified position.
int getItemCount()
Returns the number of items on the menu, including separators.
Component getMenuComponent(int n)
Returns the component at position n.
int getMenuComponentCount()
Returns the number of components on the menu.
JMenuItem insert(Action a, int pos)
Inserts a new menu item attached to the specified Action object at a given position.
JMenuItem insert(JMenuItem mi, int pos)
Inserts the specified JMenuitem at a given position.
void insert(String s, int pos)
Inserts a new menu item with the specified text at a given position.
void insertSeparator(int index)
Inserts a separator at the specified position.
boolean isPopupMenuVisible()
Returns true if the menu's popup window is visible.
boolean isSelected()
Returns true if the menu is currently selected (highlighted).
boolean isTearOff()
Returns true if the menu can be torn off.
void remove(Component c)
Removes the component c from this menu.
void remove(int pos)
Removes the menu item at the specified index from this menu.
void remove(JMenuItem item)
Removes the specified menu item from this menu.
void removeAll()
Removes all menu items from this menu.

void setSelected(boolean b)

You might also like