Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2006

Tip: Looking for answers? Try searching our database.

The simplest way to show a large output string?

Thread view: 
gabriele - 11 Jun 2006 17:09 GMT
Hi,
What I want to do is quite simple: I want to show a large output String.
The user then will press "OK"; then the output window disappears, and
the program continues.

The following code would be ok for me, but the real String I want to
show is very long (let's say 1000 characters and 100 lines), so I need
scrollbars...

Could you please tell me the simplest way to achieve this?  Thanks in
advance for your help.

==========================
package gui;
import javax.swing.*;

public class Prova {
public static void main(String[] args) {
 String s = "hello";
 JOptionPane.showMessageDialog(null, s);
 System.exit(0);
}
}
=====================
IchBin - 11 Jun 2006 18:20 GMT
> Hi,
> What I want to do is quite simple: I want to show a large output String.
[quoted text clipped - 7 lines]
> Could you please tell me the simplest way to achieve this?  Thanks in
> advance for your help.

[snip code]

How about something like this?

import java.awt.Dimension;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class Prova
{
    public static void main(String[] args)
    {
        String text = "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n";

        JPanel panel = new JPanel();
        JTextPane textPane = new JTextPane();
        JScrollPane jScrollPane = new JScrollPane(textPane);

jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        textPane.setPreferredSize(new Dimension(400, 200));
        textPane.setText(text);
        panel.add(new JScrollPane(jScrollPane));
        JOptionPane.showMessageDialog(null, panel);
        System.exit(0);
    }
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
IchBin - 11 Jun 2006 18:25 GMT
> Hi,
> What I want to do is quite simple: I want to show a large output String.
[quoted text clipped - 7 lines]
> Could you please tell me the simplest way to achieve this?  Thanks in
> advance for your help.

[snip code]

How about something like this?

import java.awt.Dimension;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class Prova
{
    public static void main(String[] args)
    {
        String text = "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n"
                + "Veryyyyyyyyyyyyyyyyyyyyyyy "
                + "Longgggggggggggggggggggggggggggggggggg"
                + "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssss\n\n";

        JPanel panel = new JPanel();
        JTextPane textPane = new JTextPane();
        JScrollPane jScrollPane = new JScrollPane(textPane);

jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        textPane.setPreferredSize(new Dimension(400, 200));
        textPane.setText(text);
        panel.add(jScrollPane);
        JOptionPane.showMessageDialog(null, panel);
        System.exit(0);
    }
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
gabriele - 11 Jun 2006 19:09 GMT
>> Could you please tell me the simplest way to achieve this?  Thanks in
>> advance for your help.
>
>[snip code]
>
>How about something like this?
[]

Thank you very much, that's exactly what i was looking for.

Bye,
Gabriele.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.