Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Over riding the Basic arrow button class in Java

Tags:

java

swing

The BasicArrowButton is a class is part of the Java SE. The BasicArrowButton Displays a Single Arrow Head in a specified direction. I want to override the class, preserving the existing methods but having the Basic Arrow Button display a double arrowhead instead of a single arrowhead. For Example See the following URL www.tiresias.org/images/ff.jpg. All I'm looking to do is to change the way this icon is drawn.

Thank you,

like image 900
Elliott Avatar asked Feb 09 '10 11:02

Elliott


2 Answers

subclass BasicArrowButton and override paintTriangle. You can try recalling BasicArrowButton's paintTriangle method twice to get the triangles. For example:

public static class Bidriectional extends BasicArrowButton {
  private static final long serialVersionUID = 1L;

  public Bidriectional() {
   // This does not matter, we'll override it anyways.
   super(SwingConstants.NORTH);
  }

  @Override
  public void paintTriangle(Graphics g, int x, int y, int size,
    int direction, boolean isEnabled) {

   super.paintTriangle(g, x - (size / 2), y, size, SwingConstants.EAST, isEnabled);
   super.paintTriangle(g, x + (size / 2), y, size, SwingConstants.EAST, isEnabled);
  }
 }

Should give you a button looking something like this:

screenshot
(source: amnet.net.au)

like image 72
Klarth Avatar answered Oct 13 '22 16:10

Klarth


Simple.

Subclass BasicArrowButton and override the paint() method and simply draw the image mentioned in your question (ff.jpg or any other image) by using g.drawImage().

Note you may need to copy ff.jpg in to your project and load it.

Note: For this you have to create a new class and use it. You cannot change the exisiting behaviour of BasicArrowButton because it does not use a UI delegate.

like image 25
Suraj Chandran Avatar answered Oct 13 '22 17:10

Suraj Chandran