CLR 123
CLR 123

Reputation: 161

Initialize Java Components in HTML

How do I create/initialize a Java variable in HTML?

I have seen uses of Java in HTML like this:

<object classid="javax.swing.JButton" label="I'm a button!"></object>

it creates a button that could for instance be displayed in a JEditorPane. However, how can I create variables and or initialize those variables/classes with constructors?

I tried for example transforming the:

new JLabel(String text);

into something like:

<object classid="javax.swing.JLabel" value="This is a label!"></object>

But no luck.

Upvotes: 0

Views: 222

Answers (1)

Thomas Kl&#228;ger
Thomas Kl&#228;ger

Reputation: 21510

You are almost there. The JavaDoc for ObjectView has the following example:

<object classid="javax.swing.JLabel">
    <param name="text" value="sample text">
</object>

You cannot pass parameters to the constructor, but with the <param name="text" value="sample text"> the code will call setText("sample text") on the created JLabel

Upvotes: 2

Related Questions