B4J Question Can i create/make use of JPanel Objects in a B4J App?

DonManfred

Expert
Licensed User
Longtime User
As the Subject already tell what i want; i want to use a JPanel-Object (created by an 3rdparty library and a wrap from me for this library) in a B4J Panel.
Is this possible? Any Example code available?

The java Examplecode is using this import basically. Plus the library-imports.

Java:
import java.awt.Color;
import javax.swing.JPanel;

Additional: Which imports (additionaljar) do i need for the two above?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Looking a little harder I did wrap it (with my usual JavaObject method) if it helps (you'll have to excuse the spaghetti code, it wasn't meant for publication as it was just a test).
 

Attachments

  • SwingNode.zip
    7.8 KB · Views: 133
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Looking a little harder I did wrap it (with my usual JavaObject method) if it helps.
Indeed it helps. Looking at the Example and the SwingNode class i would interpret it as an YES answer to my question in #1 :cool:
In fact i´ll start doing some wrapping and then lets see further into the JPanel. Now that i know it should be possible i can invest some time into the Library i want to use.
It is this one i plan to Implement (at least partially).


But under the hood the Chart must then added to an JPanel. Resp. the chartobject is a JPanel like Object.
So i need to know how to add this JPanel. Your code will surely help me in this step! Thank you for it.

I´m positive following questions will come :D
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That is on my interesting Java libraries list. I haven't had a need for it so haven't done anything about it. I'd be interested to find out how you get on with the wrap.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
That is on my interesting Java libraries list.
I found it some day ago but lack of example-sources i did not look deeper.

Today i buyed the Documentation PDF and the provided Java Example Codes... That´s the reason for this thread.
Java:
   public static JPanel createDemoPanel() {

        // create plot...
        NumberAxis xAxis = new NumberAxis("X");
        xAxis.setAutoRangeIncludesZero(false);
        NumberAxis yAxis = new NumberAxis("Y");
        yAxis.setAutoRangeIncludesZero(false);

        XYSplineRenderer renderer1 = new XYSplineRenderer();
        renderer1.setDefaultShapesVisible(false);
        XYPlot plot = new XYPlot(createSampleData(), xAxis, yAxis, renderer1);
        plot.setBackgroundPaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.WHITE);
        plot.setRangeGridlinePaint(Color.WHITE);
        plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

        // create and return the chart panel...
        JFreeChart chart = new JFreeChart("XYSplineRenderer",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        ChartUtils.applyCurrentTheme(chart);
        ChartPanel chartPanel = new ChartPanel(chart);
        return chartPanel;
    }
ChartPanel seems to extend JPanel as the return Object is declared as JPanel.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'd be interested to find out how you get on with the wrap.
I´ve created a followup beta thread for the first version of the wrapper.
 
Upvote 0
Top