1

jfreechart のデモに似たダイヤルを作成するクラスを作成しようとしています。ただし、ウィンドウがダイヤルの印刷に必要なサイズよりも小さくなった場合は、ダイヤルのあるフレームをスクロール可能にしたいと考えています。スクロール ペインを使用してこれを達成しましたが、文字盤には重量のあるコンポーネントが含まれているため、ビュー ポートの外側とスクロール バーの上に印刷され、それを使用できません。

この機能をテストするために私が書いたコードは次のとおりです。

編集:SSCCEにしようとしてコードを小さくしました(質問を投稿するのは初めてなので、まだ大きすぎる場合は申し訳ありません)

編集2:これは、私が使用している(そして使用する必要がある) jfreechart ディストリビューションの問題であることに気付きました。これは 1.0.9 です。このバグは、現在のバージョンの jfreechart では再現できません。

import java.awt.*;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.dial.*;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.*;

public class DialDoubleNeedle extends JPanel{

    private DefaultValueDataset dataset1;
    private DefaultValueDataset dataset2;
    private JFreeChart chart;
    public DialDoubleNeedle() {
        super();

        this.dataset1 = new DefaultValueDataset(0.10);
        this.dataset2 = new DefaultValueDataset(0.50);

        // get data for diagrams
        DialPlot plot = new DialPlot();
        plot.setView(0.0, 0.0, 1.0, 1.0);
        plot.setDataset(0, this.dataset1);
        plot.setDataset(1, this.dataset2);
        StandardDialFrame dialFrame = new StandardDialFrame();
        dialFrame.setBackgroundPaint(Color.lightGray);
        dialFrame.setForegroundPaint(Color.darkGray);        
        plot.setDialFrame(dialFrame);

        GradientPaint gp = new GradientPaint(new Point(), 
                new Color(255, 255, 255), new Point(), 
                new Color(170, 170, 220));

        DialBackground db = new DialBackground(gp);
        db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
        plot.setBackground(db);
        DialTextAnnotation annotation1 = new DialTextAnnotation("m/s");
        annotation1.setFont(new Font("Dialog", Font.BOLD, 14));
        annotation1.setRadius(0.7);

        plot.addLayer(annotation1);

        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setFont(new Font("Dialog", Font.PLAIN, 10));
        dvi.setOutlinePaint(Color.darkGray);
        dvi.setRadius(0.60);
        dvi.setAngle(-103.0);
        dvi.setNumberFormat(new java.text.DecimalFormat("0.00"));
        plot.addLayer(dvi);

        DialValueIndicator dvi2 = new DialValueIndicator(1);
        dvi2.setFont(new Font("Dialog", Font.PLAIN, 10));
        dvi2.setOutlinePaint(Color.red);
        dvi2.setRadius(0.60);
        dvi2.setAngle(-77.0);
        dvi2.setNumberFormat(new java.text.DecimalFormat("0.00"));
        plot.addLayer(dvi2);

        StandardDialScale scale = new StandardDialScale(0, 1, -120, -300, 0.1, 5);
        scale.setTickRadius(0.88);
        scale.setTickLabelOffset(0.15);
        scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
        plot.addScale(0, scale);

        StandardDialScale scale2 = new StandardDialScale(0, 1, -120, -300, 0.1, 5);
        scale2.setTickRadius(0.50);
        scale2.setTickLabelOffset(0.15);
        scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
        scale2.setMajorTickPaint(Color.red);
        plot.addScale(1, scale2);
        plot.mapDatasetToScale(1, 1);

        DialPointer needle2 = new DialPointer.Pin(1);
        needle2.setRadius(0.55);
        plot.addLayer(needle2);

        DialPointer needle = new DialPointer.Pointer(0);
        plot.addLayer(needle);

        DialCap cap = new DialCap();
        cap.setRadius(0.10);
        plot.setCap(cap);

        chart = new JFreeChart(plot);
        chart.setTitle("Title");
        ChartPanel cp1 = new ChartPanel(chart);
        add(cp1);


    }

    void setTitle(String title){
        chart.setTitle(title);
        return;
    }


    public static void main(final String args[]) {
        final javax.swing.JFrame test = new javax.swing.JFrame();
        test.addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(final java.awt.event.WindowEvent e) {
                System.exit(0);
            }
        });

        final JPanel jpanel1 = new JPanel();

        DialDoubleNeedle app1 = new DialDoubleNeedle();
        app1.setTitle("Tittle 1");

        jpanel1.add(app1);

        final javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();

        scrollPane.setViewportView(jpanel1);

        test.getContentPane().add(scrollPane);
        test.pack();
        test.setVisible(true);


        int i;
        Number v;   
        for(i=0; i<1000000000; i++){
            if(i==(1000000000-1)){
                i=0;
                v=app1.dataset1.getValue();
                app1.dataset1.setValue(v.doubleValue()+0.01);
            }
        }

    }
}

上記のコードをコンパイルすると、実行時に問題なく表示されることがわかりますが、縮小すると、最終的にダイヤル パーツの一部 (重量のあるパーツ) がスクロール バーの上に表示されます。これを修正するにはどうすればよいですか?

4

1 に答える 1