Friday, 11 April 2014

AdjustmentEvent

The adjustment event emitted by Adjustable objects like Scroll Bar, Scroll Pane. When the user changes the value of the scrolling component, it receives an instance of AdjustmentEvent.

Methods in AdjustmentEvent class

public Adjustable getAdjustable()
Returns the Adjustable object where this event originated. Adjustable Object gives the details about Minimum and Maximum values of the adjustable object, Orientation(like HORIZONTAL, VERTICAL, NO_ORIENTATION ) Of the Adjustable Object etc.,

public int getValue()
Returns the current value in the adjustment event.

public int getAdjustmentType()
Returns the type of adjustment which caused the value changed event.1 represents UNIT_INCREMENT, 2 represents UNIT_DECREMENT, 3 represents BLOCK_DECREMENT, 4 represents BLOCK_INCREMENT, 5 represents TRACK.

public boolean getValueIsAdjusting()
Returns true if this is one of multiple adjustment events.

public String paramString()
Returns a string representing the state of this Event. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AdjustmentEventEx{
 JTextArea displayArea;
 JFrame frame1;
  
 AdjustmentEventEx(){
  JScrollBar bar = new JScrollBar(SwingConstants.VERTICAL, 50, 10, 0, 100);
 
  /* Initialize Display Area */
  displayArea = new JTextArea();
  displayArea.setEditable(false);
  JScrollPane scrollPane = new JScrollPane(displayArea);
  scrollPane.setPreferredSize(new Dimension(450, 150));
   
  /* Initialize Frame */
  frame1 =new JFrame("Sample Frame");
  frame1.pack();
  frame1.setVisible(true);
  frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame1.getContentPane().add(bar, BorderLayout.WEST);
  frame1.getContentPane().add(scrollPane, BorderLayout.CENTER);
  frame1.setSize(800, 600);
    
  bar.addAdjustmentListener(new AdjustmentListener(){
   public void adjustmentValueChanged(AdjustmentEvent  e){
    Adjustable adjustableObj = e.getAdjustable();
    displayArea.append("\n\nAdjustable Object info");
    
    /* represents HORIZONTAL, \n 1 represents VERTICAL, \n2 represents NO_ORIENTATION */
    displayArea.append("\nOrientation Of the Object is  " + adjustableObj.getOrientation());
    displayArea.append("\nminimum value of the adjustable object " + adjustableObj.getMinimum());
    displayArea.append("\nmaximum value of the adjustable object " + adjustableObj.getMaximum());
    displayArea.append("\nunit value increment for the adjustable object " + adjustableObj.getUnitIncrement());
    displayArea.append("\nblock value increment for the adjustable object " + adjustableObj.getBlockIncrement());
    displayArea.append("\nlength of the proportional indicator " + adjustableObj.getVisibleAmount());
    displayArea.append("\ncurrent value of the adjustable object " + adjustableObj.getValue());
    
    displayArea.append("\ncurrent value in the adjustment event " + e.getValue());
    displayArea.append("\ntype of adjustment " + e.getAdjustmentType());
    displayArea.append("\nIs one of adjustment events " + e.getValueIsAdjusting());
    displayArea.append("\nparamString is " + e.paramString()); 
   }
  }); 
 }
 
 public static void main(String args[]){
  new AdjustmentEventEx();
 }
}







Prevoius                                                 Next                                                 Home

No comments:

Post a Comment