How to use JScrollBar class?
Hello Guys,
I am new to the java programming. I am getting trouble while understanding the concept of 'JScrollBar class'. So need I need your help to be aware about the functionality of JScrollBar class of java. I also want be aware about the constructors and methods of JScrollBar class. If you have enough knowledge about the JScrollBar class of java, then please let me know the same. Your any help over JScrollBar class will be greatly appreciated.
Re: How to use JScrollBar class?
A JScrollBar class used for an implementation of a scrollbar. The user positions the knob in the scrollbar to determine the contents of the viewing area. The program typically adjusts the display so that the end of the scrollbar represents the end of the displayable contents, or 100% of the contents. The start of the scrollbar is the beginning of the displayable contents, or 0%. The position of the knob within those bounds then translates to the corresponding percentage of the displayable contents.
Re: How to use JScrollBar class?
Hi,
Please following example of JScrollBar class of java:
Code:
import javax.swing.JScrollBar;
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class JScrollBarDM {
public static void main(String argsn[]) throws Exception {
JFrame FL = new JFrame();
FL.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
FL.add(oneJScrollBar, BorderLayout.NORTH);
FL.setSize(300, 44);
FL.setVisible(true);
}
}
Re: How to use JScrollBar class?
Following are some most important methods of the JScrollBar class, please review them carefully:
- setVisibleAmount(int extnt)
- setValues(int newValue, int newExtnt, int Min, int Max)
- setValueIsAdjusting(boolean bl)
- setUnitIncrement(int unitIncrmnt)
- setOrientation(int orn)
- setModel(BoundedRangeModel newMdl)
Re: How to use JScrollBar class?
Hello friend,
Below is the java code which is show you how to use methods of JScrollBar class:
Code:
import javax.swing.JScrollBar;
public class JSMainClass {
public static void main(String argsp[]) throws Exception {
AdjustmentListener adjustmentListener = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
System.out.println("Adjusted: " + adjustmentEvent.getValue());
}
};
JScrollBar oneJScrollBar1 = new JScrollBar(JScrollBar.HORIZONTAL);
oneJScrollBar1.addAdjustmentListener(adjustmentListener);
JFrame GW = new JFrame("ScrollBars R Us");
GW.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GW.add(oneJScrollBar, BorderLayout.NORTH);
GW.setSize(300, 200);
GW.setVisible(true);
}
}
Re: How to use JScrollBar class?
Hi,
I suggest you to go through following constructors of JScrollBar class:- JScrollBar(): This constructor is used for the creation of vertical scrollbar
- JScrollBar(int ortn):This constructo is used for the creation of scrollbar with a particular specification
- JScrollBar(int orientation, int val, int extnt, int min1, int max1): This constructor is used for the creation of scrollbar with a particular specification such as max, min.
Re: How to use JScrollBar class?
Following are some nested classes of the JScrollBar class, please review them carefully:
- JScrollBar.AccessibleJScrollBar
- Component.BltBufferStrategy
- JComponent.AccessibleJComponent
- Component.AccessibleAWTComponent
- Container.AccessibleAWTContainer