JGrid Tutorial #4
#Swing
In this tutorial we want to add zoom functionality to the JGrid. You can set the dimension of the grid cells be the property fixedCellDimension
. Here is a example for two different dimensions:
To add a zoom functionality to the grid you can set the dimension by using a JSlider. Here is the code:
final JSlider slider = new JSlider(32, 256);
slider.setValue(grid.getFixedCellDimension());
slider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
grid.setFixedCellDimension(slider.getValue());
}
});
Now you can edit the dimension dynamically. Here is the result:
You can download the source file here.
Hendrik Ebbers
Hendrik Ebbers is the founder of Open Elements. He is a Java champion, a member of JSR expert groups and a JavaOne rockstar. Hendrik is a member of the Eclipse JakartaEE working group (WG) and the Eclipse Adoptium WG. In addition, Hendrik Ebbers is a member of the Board of Directors of the Eclipse Foundation.