Swing Method & Constructors

Table Default List Model Constructors and Methods
Constructors Description
DefaultListModel() Create a new list model object
Method Description
boolean Contains(Object ele) Returns true if the specified element is in the list
int size() Returns the number of elements in the list
void add(Object ele, int index) Adds an element at a specified position
void clear() Removes all elements from the list
void addElement(Object ele) Adds an element to the end of the list
void remove(int index) Removes a element from the specified position in the list
void removeElement(Object ele) Removes the specified element from the list
Object firstElement() Returns the first element in the list
Object get(int index) Returns a element at the specified location
boolean isEmpty() Returns true if the list is empty
Object lastElement() Returns the last element in the list
Object[] toArray() Returns an array containing each element in the list

 

Table JSpinner, Related and SpinnerModel classes
Constructor Description
JSpinner() Creates a default spinner
JSlider(SpinnerModel model) Creates a spinner using a specified Spinner Model object
SpinnerNumberModel(double max, double step) Creates a number spinner model which lets the user select double values from min to max with an increment of step
SpinnerNumberModel(int init, int min, int max, int step) Creates a number spinner model which lets the user select integer values from min to max with an increment of step, with an initial value at initi
SpinnerlistModel(Object[] val) Creates a list spinner model using the values from the specified array
SpinnerListModel(List collect) Creates a list of spinner model using the values from a specified collection
Method Description
int getValue() Gets the value
void addChangeListener(ChangeListener listen) Adds a change listener to listen for the events
void setToolTipText(String txt) Sets the tooltip text that's displayed if the user rests the mouse over the slider

 

Table JTree Constructors and Methods
Constructor Description
void JTree() Creates an empty tree
void JTree(TreeNode root) Creates a tree which displays the tree that starts at the specified node
Method Description
TreeSelectionModel getSelectionModel() Gets the selection model for the tree.
Object getLastSelectedPathComponent() Gets the node that is currently selected
void addTreeSelectionListener(TreeSelectionListener llistener) Adds a listener to list for tree selection events
void setVisibleRowCount(int count) Sets the number of rows visible in the display

 

Table Default Mutable Tree Node Class
Constructor Description
DefaultMutableTreeNode() Creates an empty tree node
DefaultMutableTreeNode(Object user) Creates a tree node with a specified user object
Method Description
TreeNode getParent() Gets this node's parent
Object getUserObject() Gets the user object for this node
TreeNode getFirstChild() Gets the first of this node's children
DefaultMutableTreeNode getNextSibling() Gets the next sibling
void add(TreeNode child) Adds a child node

 

Table BorderFacotry Methods for Creating Borders
Method Description
Border createBevelBorder(int type) Creates a bevel border of the specified type. The parameter type can be: BevelBorder.LOWERED or BevelBorder.RAISED
Border createLineBorder() Creates a line border
Border createLoweredBevelBorder() Creates a lowered bevel border
Border creaetRaisedBevelBorder() Creates a raised bevel border
Border createEthchedBorder() Creates an etched border
Border createEmptyBorder(int top, int left, int bottom, int right) Creates an empty border that occupies the space indicated by the parameter
Border createTitledBorder(String title) Creates a titled etched border
Border createTitledBorder(Border b, String title) Creates a titled border from the specified border

 

Table Border Layout Constructors and Fields
Constructor Description
BorderLayout() Creates a new border layout with no gaps
BorderLayout(int hgap, int vgap) Creates a new border layout with a specified horizontal and vertical gaps
Field Description
NORTH The north region of the border layout ( at the top of the container )
SOUTH The south region of the border layout ( at the bottom of the container )
WEST The west region of the border layout ( at the left of the container )
EAST The east region of the border layout ( at the right of the container )
CENTER The center region ( at the center of the container )
   

 

Table The Box and Dimension Classes
Box Methods Description
static Component createHorizontalGlue() Creates a horizontal glue component.
static Component createHorizontalStrut( int width) Creates a horizontal strut component that places the specified amount of space between the components on either side of it
static Component createGlue() Creates a glue component. This component forces the components on any side of it as far away from each other as possible
static Box createHorizontalBox() Creates a horizontal box
static createRigidArea(dimension d) Creates an area with a fixed size
static Box createVerticalBox() Creates a vertical box
static Component createVerticalGlue() Creates a vertical glue component
static Component createVerticalStrut Creates a vertical strut component
Dimension Constructor Description
Dimension(int wid, int height) Creates a new Dimension object with a specified width and height

 

Table FlowLayout Constructors
Constructor Description
FlowLayout() Creates a new flow layout
FlowLayout(int align) Creates a new flow layout with a specified alignment. The parameters can be:

FlowLayout.LEFT,  FlowLayout.CENTER, or FlowLayout.RIGHT

FlowLayout(int align, int hgap, int vgap) Creates a new flow layout with a specified alignment and specified horizontal and vertical gaps

 

Table GridLayout Constructor
Constructor Description
GridLayout() Creates a new grid layout which arranges the components in a single row
GridLayout(int rows, int col) Creates a new grid layout with a specified number of rows and columns
GridLayout(int rows, int col, int hgap, int vgap) Creates a new grid layout with a specified number of rows and columns with gaps of the specified size between rows and columns

 

Table Grid Bag Contraints Class
Field Description
int gridx The x position of the component
int gridy The y position of the component
int gridwidth The number of columns spanned by the component
int gridheight The number of rows spanned by the component
int fill A constant that indicates whether to stretch the object to fill available space. Values can be:  GridBagConstraints class: HORIZONTAL, NONE,  VERTICAL or BOTH
int anchor A constant that indicates where to place the component if it doesn't fill the space. Vales can be:

GridBagConstraints class: CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WETS, and, NORTHWEST

double weightx A value that gives the grid layout a hint how to apportion space for the component's width
double weighty A value that gives the grid layout a hint how to apportion space for the component's height
Insets insets An insets object that indicates how much space to use as padding around each component.

 

Table JApplet Constructors and Methods
Constructor Description
JApplet Create a new applet
Method Description
void init() Called by the browser informing the applet that is has been loaded
void add(Component c) Adds a specified component to the applet
void destroy() Called by the browser to inform the applet that its memory is about to be reclaimed by the JVM.
void setLayout(LayoutManager layout Sets the layout of the applet
void setLocation(int x, int y) Sets the x and y position of the applet
void setLocationRelativeTo(Component c) Sets the start location of the applet, center if it is null
void setSize(int wid, int height) Sets the size of the applet to the specified width and height
void setJMenuBar(JMenuBar menu) Sets the menu for the applet
void start() Called by the browser to inform the applet to start
void stop() Called by the browser when the applet temporarily leaves view

 

<Previous><Java 24><Home><Swing>