Java JScrollBar Example

Java JScrollBar Example

Java JScrollBar Example
Java JScrollBar is used to add vertical or horizontal scroll bars.ScrollBar inherits methods from JComponent class.

How to Declare Java JScrollBar

[class JScrollBar extends JComponent implements Adjustable, Accessible]

Java JScrollBar  used constructors

  • JScrollBar()-creates vertical scrollbar with initial values.
  • JScrollBar(int orientation)-creates scrollbar with a certain orientation and initial values.
  • JScrollBar(int orientation,int v,int extent,int max,int min)-creates JScrollBar with specified values.

Java JScrollBar Example

[
import javax.swing.JFrame;
import javax.swing.JScrollBar;
public class JavaJScrollBarExample extends JFrame {
    JavaJScrollBarExample ()
    {
        super("JavaJScrollBarExample ");

        JScrollBar scroll=new JScrollBar();
        scroll.setBounds(50,50, 50,100);
        add(scroll);


        setSize(400,400);
        setLayout(null);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);

    }
    public static void main(String args[])
    {
        new JavaJScrollBarExample ();
    }

}
]


Code Explanation

[ super("JavaJScrollBarExample ");] -this code calls the JFrame constructor which has been extended in this class.
[ JScrollBar scroll=new JScrollBar();]-Creates JScrollbar object.
[setDefaultCloseOperation(EXIT_ON_CLOSE);]-exits application when the close button is clicked.


Java JScrollBar Example with Adjustment Listener

[
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import javax.swing.JOptionPane;
public class JavaJScrollBarExample extends JFrame
        implements AdjustmentListener {
    JavaJScrollBarExample ()
    {
        super("JavaJScrollBarExample ");

        JScrollBar scroll=new JScrollBar();
        scroll.setBounds(50,50, 50,100);
        add(scroll);

        scroll.addAdjustmentListener(this);

        setSize(400,400);
        setLayout(null);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);

    }
    public void adjustmentValueChanged(AdjustmentEvent evt)
    {
        JOptionPane.showMessageDialog(null, "Vertical scrollbar "                  
      +evt.getValue(),"JScrollBar Example",
                JOptionPane.INFORMATION_MESSAGE);
    }
    public static void main(String args[])
    {
        new JavaJScrollBarExample ();
    }

}
]

Output
Java JScrollBar Example
Code Explanation
Above class extends JFrame and implement AdjustmentListener interface [public class JavaJScrollBarExample extends JFrame
implements AdjustmentListener ]

If a non abstract class implements a certain interface,the class is required to override all interface abstract methods.For example AdjustmentListener abstract method is [public void adjustmentValueChanged(AdjustmentEvent evt)
    {
        JOptionPane.showMessageDialog(null, "Vertical scrollbar "                     
   +evt.getValue(),"JScrollBar Example",
                JOptionPane.INFORMATION_MESSAGE);
    }
]

The user scrolls the JScrollBar action is picked which invokes [ JOptionPane.showMessageDialog()] method.JOptionPane pop ups showing value of vertical scrollbar position.

Other methods used in this program

[setBounds(50,50, 50,100);]-positions java.swing components in JFrame or JPanel.
[setDefaultCloseOperation(EXIT_ON_CLOSE);]-exits application when close button is clicked.
[ setLocationRelativeTo(null);]-positions JFrame at the center of the screen.


COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Java JScrollBar Example
Java JScrollBar Example
Java JScrollBar Example
https://1.bp.blogspot.com/-q41XmXHS9YQ/WMf6UPST9OI/AAAAAAAAHLU/_o38RZatPrgwrv5elcvpmgiFnMRcyrK-QCLcB/s200/Java-JScrollBar-Example-min.PNG
https://1.bp.blogspot.com/-q41XmXHS9YQ/WMf6UPST9OI/AAAAAAAAHLU/_o38RZatPrgwrv5elcvpmgiFnMRcyrK-QCLcB/s72-c/Java-JScrollBar-Example-min.PNG
Java Codes
http://www.download-all.net/2017/03/java-jscrollbar-example.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/03/java-jscrollbar-example.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy