Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » displaying HTML in dialog
displaying HTML in dialog [message #447078] Wed, 08 December 2004 15:12 Go to next message
Eclipse UserFriend
Originally posted by: ps7.bolton.ac.uk

Hi,

I want to open a kind of confirmation (ok button) dialog which will
display/render a HTML string message. Heres how I did it in swing -
with a JLabel...

JLabel box = new JLabel();
box.setVerticalAlignment(SwingConstants.TOP);
// pd.getLogResults() returns a HTML string ie <html><body>etc....
box.setText(pd.getLogResults());
JScrollPane sp = new JScrollPane(box);
sp.setPreferredSize(new Dimension(350, 400));
JOptionPane.showMessageDialog(MyApplication.getInstance(), sp,
"Completed", JOptionPane.PLAIN_MESSAGE);

How can I do this in swt? I tried using swt Label but it didnt seem to
work.

Thanks for your time

Paul
Re: displaying HTML in dialog [message #447107 is a reply to message #447078] Wed, 08 December 2004 17:18 Go to previous messageGo to next message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 396
Registered: July 2009
Senior Member
Paul Sharples wrote:
> Hi,
>
> I want to open a kind of confirmation (ok button) dialog which will
> display/render a HTML string message. Heres how I did it in swing -
> with a JLabel...
>
> JLabel box = new JLabel();
> box.setVerticalAlignment(SwingConstants.TOP);
> // pd.getLogResults() returns a HTML string ie <html><body>etc....
> box.setText(pd.getLogResults());
> JScrollPane sp = new JScrollPane(box);
> sp.setPreferredSize(new Dimension(350, 400));
> JOptionPane.showMessageDialog(MyApplication.getInstance(), sp,
> "Completed", JOptionPane.PLAIN_MESSAGE);
>
> How can I do this in swt? I tried using swt Label but it didnt seem to
> work.
>
> Thanks for your time
>
> Paul
>
Paul,

The SWT Browser Widget is the only SWT component capable of displaying
html out of the box. Have you looked into using it?

- Jeff
Re: displaying HTML in dialog [message #447129 is a reply to message #447107] Wed, 08 December 2004 23:20 Go to previous messageGo to next message
lars gersmann is currently offline lars gersmannFriend
Messages: 4
Registered: July 2009
Junior Member
hi,

you can displaya limited set of html using the eclipse 3.0 forms api:

StringBuffer buf = new StringBuffer();
buf.append("<form>");
buf.append("<p>");
buf.append("Here is some plain text for the text to render; ");
buf.append("this text is at <a href=\"http://www.eclipse.org\"
nowrap=\"true\">http://www.eclipse.org</a> web site.");
buf.append("</p>");
buf.append("<p>");
buf.append("<span color=\"header\" font=\"header\">This text is in header
font and color.</span>");
buf.append("</p>");
buf.append("<p>This line will contain some <b>bold</b> and some <span
font=\"text\">source</span> text. ");
buf.append("We can also add <img href=\"image\"/> an image. ");
buf.append("</p>");
buf.append("<li>A default (bulleted) list item.</li>");
buf.append("<li>Another bullet list item.</li>");
buf.append("<li style=\"text\" value=\"1.\">A list item with text.</li>");
buf.append("<li style=\"text\" value=\"2.\">Another list item with
text</li>");
buf.append("<li style=\"image\" value=\"image\">List item with an image
bullet</li>");
buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\"
value=\"3.\">A list item with text.</li>");
buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\"
value=\"4.\">A list item with text.</li>");
buf.append("</form>");
FormText rtext = toolkit.createFormText(form.getBody(), true);
td = new TableWrapData(TableWrapData.FILL);
td.colspan = 2;
rtext.setLayoutData(td);
rtext.setImage("image",
ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesP lugin.IMG_SAMPLE));
rtext.setColor("header", toolkit.getColors().getColor(FormColors.TITLE));
rtext.setFont("header", JFaceResources.getHeaderFont());
rtext.setText(buf.toString(), true, false);
rtext.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
System.out.println("Link active: "+e.getHref());
}
});

see
http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/pde-ui-h ome/working/EclipseForms/EclipseForms.html

for usage.

regards,

lars

Jeff Myers wrote:

> Paul Sharples wrote:
>> Hi,
>>
>> I want to open a kind of confirmation (ok button) dialog which will
>> display/render a HTML string message. Heres how I did it in swing -
>> with a JLabel...
>>
>> JLabel box = new JLabel();
>> box.setVerticalAlignment(SwingConstants.TOP);
>> // pd.getLogResults() returns a HTML string ie <html><body>etc....
>> box.setText(pd.getLogResults());
>> JScrollPane sp = new JScrollPane(box);
>> sp.setPreferredSize(new Dimension(350, 400));
>> JOptionPane.showMessageDialog(MyApplication.getInstance(), sp,
>> "Completed", JOptionPane.PLAIN_MESSAGE);
>>
>> How can I do this in swt? I tried using swt Label but it didnt seem to
>> work.
>>
>> Thanks for your time
>>
>> Paul
>>
> Paul,

> The SWT Browser Widget is the only SWT component capable of displaying
> html out of the box. Have you looked into using it?

> - Jeff
Re: displaying HTML in dialog [message #447135 is a reply to message #447129] Thu, 09 December 2004 00:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ps7.bolton.ac.uk

Thanks to both of you.

Yes I'd read a little about the forms API and have used the Browser
widget a little before - so it will have to be one of those I guess. I'd
just wondered if there was something comparable to the swing version -
but I guess not.

Thanks again.

Paul

lars gersmann wrote:
> hi,
>
> you can displaya limited set of html using the eclipse 3.0 forms api:
>
> StringBuffer buf = new StringBuffer();
> buf.append("<form>");
> buf.append("<p>");
> buf.append("Here is some plain text for the text to render; ");
> buf.append("this text is at <a href=\"http://www.eclipse.org\"
> nowrap=\"true\">http://www.eclipse.org</a> web site.");
> buf.append("</p>");
> buf.append("<p>");
> buf.append("<span color=\"header\" font=\"header\">This text is in
> header font and color.</span>");
> buf.append("</p>");
> buf.append("<p>This line will contain some <b>bold</b> and some
> <span font=\"text\">source</span> text. ");
> buf.append("We can also add <img href=\"image\"/> an image. ");
> buf.append("</p>");
> buf.append("<li>A default (bulleted) list item.</li>");
> buf.append("<li>Another bullet list item.</li>");
> buf.append("<li style=\"text\" value=\"1.\">A list item with
> text.</li>");
> buf.append("<li style=\"text\" value=\"2.\">Another list item with
> text</li>");
> buf.append("<li style=\"image\" value=\"image\">List item with an
> image bullet</li>");
> buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\"
> value=\"3.\">A list item with text.</li>");
> buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\"
> value=\"4.\">A list item with text.</li>");
> buf.append("</form>");
> FormText rtext = toolkit.createFormText(form.getBody(), true);
> td = new TableWrapData(TableWrapData.FILL);
> td.colspan = 2;
> rtext.setLayoutData(td);
> rtext.setImage("image",
> ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesP lugin.IMG_SAMPLE));
>
> rtext.setColor("header",
> toolkit.getColors().getColor(FormColors.TITLE));
> rtext.setFont("header", JFaceResources.getHeaderFont());
> rtext.setText(buf.toString(), true, false);
> rtext.addHyperlinkListener(new HyperlinkAdapter() {
> public void linkActivated(HyperlinkEvent e) {
> System.out.println("Link active: "+e.getHref());
> }
> });
>
> see
> http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/pde-ui-h ome/working/EclipseForms/EclipseForms.html
>
>
> for usage.
>
> regards,
>
> lars
>
> Jeff Myers wrote:
>
>> Paul Sharples wrote:
>>
>>> Hi,
>>>
>>> I want to open a kind of confirmation (ok button) dialog which will
>>> display/render a HTML string message. Heres how I did it in swing -
>>> with a JLabel...
>>>
>>> JLabel box = new JLabel();
>>> box.setVerticalAlignment(SwingConstants.TOP);
>>> // pd.getLogResults() returns a HTML string ie <html><body>etc....
>>> box.setText(pd.getLogResults());
>>> JScrollPane sp = new JScrollPane(box);
>>> sp.setPreferredSize(new Dimension(350, 400));
>>> JOptionPane.showMessageDialog(MyApplication.getInstance(), sp,
>>> "Completed", JOptionPane.PLAIN_MESSAGE);
>>>
>>> How can I do this in swt? I tried using swt Label but it didnt seem
>>> to work.
>>>
>>> Thanks for your time
>>>
>>> Paul
>>>
>> Paul,
>
>
>> The SWT Browser Widget is the only SWT component capable of displaying
>> html out of the box. Have you looked into using it?
>
>
>> - Jeff
>
>
>
Re: displaying HTML in dialog [message #447143 is a reply to message #447078] Thu, 09 December 2004 04:37 Go to previous message
Eclipse UserFriend
Originally posted by: no.ddress.here

In article <cp75ku$kmo$1@www.eclipse.org>, ps7@bolton.ac.uk says...
> Hi,
>
> I want to open a kind of confirmation (ok button) dialog which will
> display/render a HTML string message. Heres how I did it in swing -
> with a JLabel...
>
> JLabel box = new JLabel();
> box.setVerticalAlignment(SwingConstants.TOP);
> // pd.getLogResults() returns a HTML string ie <html><body>etc....
> box.setText(pd.getLogResults());
> JScrollPane sp = new JScrollPane(box);
> sp.setPreferredSize(new Dimension(350, 400));
> JOptionPane.showMessageDialog(MyApplication.getInstance(), sp,
> "Completed", JOptionPane.PLAIN_MESSAGE);
>
> How can I do this in swt? I tried using swt Label but it didnt seem to
> work.
>
> Thanks for your time
>
> Paul
>
>

Paul,

You can always embed Swing in SWT. Check out SWT example snippet 125.
As an example, this snippet embeds a JEditorPane in a Composite in an
SWT form.


toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createForm(parent);
GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);
/////////////////////////////
Composite composite1 = toolkit.createComposite(form.getBody(),
SWT.EMBEDDED);
GridLayout composite1Layout = new GridLayout();
composite1Layout.makeColumnsEqualWidth = true;
GridData composite1LData = new GridData();
composite1LData.grabExcessHorizontalSpace = true;
composite1LData.grabExcessVerticalSpace = true;
composite1LData.horizontalAlignment = GridData.FILL;
composite1LData.verticalAlignment = GridData.FILL;
composite1.setLayoutData(composite1LData);
composite1.setLayout(composite1Layout);

/////////////////////////////
Frame locationFrame = SWT_AWT.new_Frame(composite1);
Panel jPanel1 = new java.awt.Panel();
locationFrame.add(jPanel1);
BorderLayout panelLayout = new BorderLayout();
jPanel1.setLayout(panelLayout);
jScrollPane1 = new JScrollPane();
jPanel1.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.setVerticalScrollBarPolicy
(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

jEditorPane1 = new JEditorPane();
jScrollPane1.setViewportView(jEditorPane1);
jEditorPane1.setContentType("text/html");
jEditorPane1.setText("jEditorPane1");
jEditorPane1.setEditable(false);

Regards,
Gerald
Previous Topic:Unable to select JTable rows??
Next Topic:Swing Table to SWT Table
Goto Forum:
  


Current Time: Wed Apr 24 20:02:22 GMT 2024

Powered by FUDForum. Page generated in 0.02770 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top