Scrollable Text Component

I need to make a scrollable text component which reads characters from an InputStream object. I have two questions.
Q1: My first attempt was to make a Text Area but I couldn't find any ways to easily make it scrollable. The method in the JTextComponent class that returns the scrollable object needs a Rectangle object in its paramaters. But I don't have a Rectangle object, I have a Text Area object. This gets me thinking that perhaps I should be using a different object than a Text Area. So, what class/object should I use from the API to make a scrollable text component?
Q2: I want this scrollable Text Component to read characters from an InputStream object. How can I do this easily?

* SaveReloadText.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class SaveReloadText extends JFrame {
    public SaveReloadText() {
        initComponents();
    private void initComponents() {
        setTitle("Save-Reload JTextArea");
        toolbar = new JToolBar();
        saveButton = new JButton("Save");
        reloadButton = new JButton("Reload");
        reloadButton.setEnabled(false);
        textarea = new JTextArea();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        saveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                saveButtonActionPerformed(evt);
        toolbar.add(saveButton);
        reloadButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                reloadButtonActionPerformed(evt);
        toolbar.add(reloadButton);
        getContentPane().add(toolbar, BorderLayout.NORTH);
        textarea.setBackground(new Color(204, 204, 204));
        textarea.setText(
                "BLA BLA BLA\n" +
                "\n" +
                "bla bla bla bla bla bla bla bla blabla bla bla  bla bla bla, \n" +
                "bla bla bla bla bla bla bla bla blabla bla bla  bl, etc. \n" +
                "\n" +
                "Bla bla bla bla bla bla bla bla blabla bla bla  bla bla bla bla bla. \n" +
                "\n" +
                "Bla bla bla bla bla bla bla bla blabla bla bla  bla bla bla, \n" +
                "bla bla bla bla bla bla bla bla blabla bla bla  bla bla bla bla bla bla blabla. \n" +
                "Bla bla bla bla . \n" +
                "\n" +
                "bla bla bla bla bla bla,  bla bla blabla bla bla . \n" +
                "\n" +
                "bla bla bla bla bla bla bla bla blabla bla bla  bla bla bla bla bla  bla bla bla \n" +
                "bla bla bla, blahhhhhhhhhhh. "
        getContentPane().add(new JScrollPane(textarea), BorderLayout.CENTER);
        setSize(300,200);
        setLocationRelativeTo(null);
    private void saveButtonActionPerformed(final ActionEvent evt) {
        try{
            doSave();
        }catch(IOException ex){
            ex.printStackTrace();
            return;
        textarea.setText("");
        saveButton.setEnabled(false);
        reloadButton.setEnabled(true);
    private void reloadButtonActionPerformed(final ActionEvent evt) {
        try{
            doReload();
        }catch(IOException ex){
            ex.printStackTrace();
            return;
        saveButton.setEnabled(true);
        reloadButton.setEnabled(false);
    private void doSave() throws IOException{
        Writer writer = new BufferedWriter(new FileWriter(new File(FILE_NAME)));
        textarea.write(writer);
        writer.close();
    private void doReload() throws IOException{
        Reader reader = new BufferedReader(new FileReader(new File(FILE_NAME)));
        textarea.read(reader,null);
        reader.close();
    public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SaveReloadText().setVisible(true);
    private final String FILE_NAME = "c:\\Masturbation_Technique.txt";
    private BufferedWriter writer;
    private BufferedReader reader;
    private JButton saveButton,reloadButton;
    private JTextArea textarea;
    private JToolBar toolbar;
}

Similar Messages

  • Scrollable text for device

    Hi, im new here
    im an designer, not a programmer, but CodeSnippets make me real happy%)
    but i dont know how to create a scrollable text in AIR for device,someone, pls, tell!

    use a textarea component.

  • How to email text from a text component in my applet on a the host server ?

    How to email text from a text component in my applet on a the host server, back to my email address ?
    Assuming I have Email Form on the host server.
    Help will be appreciated.

    You can do like below
    =REPLACE(Fields!Column.Value," " & Parameters!ParameterName.value & " ","<b>" & Parameters!ParameterName.value & "</b>")
    The select the expression and  right click and choose placeholder properties
    Inside that set Markup type as HTML 
    then it will highlight the passed parameter value in bold within the full xml string
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Problems trying to create scrollable text in InDesign CC

    I'm making an interactive presentation in InDesign. Im trying to create some scrollable text. i didn't know how to do that in CC, so I looked up some videos over the web and learned I needed to use the "Folio Builder" or the "Overlay panel". i never was able to find the latter and the Folio Builder gives me this message: "A software update is required to use Digital Publishing Suite. Please go to the Help menu and select Updates to get the required software." My software is already up-to-date (at least that's what the Adobe Application Manager tells me). Is this happening because I'm using a trial version? I'm planning to buy the Creative Cloud package but first I need to know it's worthy. Thanks for your help!

    You are most likely looking at some very old videos. As it happens my DPS
    course was just released on lynda.com:
    http://boblevine.us/my-first-lynda-com-title-adobe-digital-publishing-suite-
    essential-training-is-live/
    There's a link to a one week trial there if you don't have a subscription.

  • Preview and scrollable text problems

    Is anyone else having problems getting the scrollable text function to work in an overlay to a fixed layout ePub? I have the latest version of InDesign CC, purchased last week.
    Here is a picture of my file. As you can see, it's pretty darn simple. Content box is on the right. You can't see the entire box but It is long enough to fit all of my text. On the left, I created a container box, wider but shorter than the content box. I then selected the content and used Paste Into to put the content into the container. Next, I selected the container, went to Folio Overlays, and I designated the content box as vertical scrolling, start at upper left, and Vector format. But when when I tried to preview it (more on preview problems in a minute), the container appears as a simple text box with no scrolling capability. I've asked the Adobe help people and they don't seem to have any ideas yet.
    As far as preview goes, well, I can export to Adobe Digital Editions or I can look at the page in Window/Interactive/EPUB Interactivity Preview. But File/Folio Preview just processes the page and then returns nothing. And the same thing happens when I hit Preview in the Folio Overlays panel.
    I'd love to know if this is unique to my system or a common problem. Since I only purchased CC to produce annotated books, there is not much I can do without it. And if CC doesn't do it, does anyone have a suggestion for something a non-programmer could use to get the same result?
    Thanks for any help.

    Scrollable frames are a DPS -- Digital Publishing Suite-- function (as are all other effects from the Folio Overlay panel). Those are a different beast than Fixed-Layout EPUBs.
    For fixed-layout, all interactivity is supported (any panel in the Windows > Interactive flyout) except for Forms, Page Transitions, and the two Animation presets Smoke and Blur. Note that the panels Folio Builder and Folio Overlays are not part of the Interactive group of panels.
    I know it's very confusing!
    If you're trying to create an *app* then you use DPS, and you should be asking this question in the DPS forum.
    Digital Publishing Suite
    If you're trying to create an *ebook* then this is the forum to post in. 
    You might find my new lynda.com video tutorial course, Creating Fixed Layout EPUBs from InDesign CC, to be helpful. A bunch of the videos are free and may be all you need. To watch the others, though, you'll need a subscription. You can use my Free Pass URL to get a free week of open access to all the lynda.com videos.
    Watch the Online Video Course Creating Fixed-Layout EPUBs with InDesign CC
    Free pass: http://lynda.com/freepass/amconcepcion
    AM

  • Word processing within a text component

    Although this is a potentially great application, I am at present prevented from using it to create a website due to the lack, as far as I can determine, of any form of processing individual text within the text components e.g. making individual words or word groups bold or italic or giving them COLORS.
    I have large informatory text areas on my pages which need this sort of processing in order to avoid client eyestrain as well as my own.
    Of course one can get around this to some extent by using multiple components but for long texts this quickly becomes very tedious and error prone, especially if one wants to copy from another source.
    The Static Text component, which I presume is meant for this sort of text, in it's present simple form allows word wrap but no line formatting. The basic Text Area component (multiple lines) has no word wrap but does allow line formatting. However when one sets the Read Only property, it seems that any self created line formatting is duly destroyed. This is strangely not the case with the old Standard Mutliline Text Area component.
    I may be missing something but if not I hope that these features may yet be incorporated.
    Regards,
    Dave

    You can use static text to render pure HTML, just set "escape" property to false.
    Note that the HTML text must be well former.
    Regards.

  • Center text in a text component with line wrapping

    I need to display dynamic text in a text component. I need line wrapping (on work boundaries) and also need horizontal and vertical center alignment.
    How do I do this? I saw a previous post on aligning text in a JTextArea that said to use a JTextPane but I don't see in JTextPane how to do word wrapping.
    Thanks,
    John

    //  File:          SystemInfoWindow.java.java
    //  Classes:     SystemInfoWindow
    //  Package:     utilities.msglib
    //  Purpose:     Implement the SystemInfoWindow class.
    //     Author:          JJB 
    //     Revision History:
    //     Date            By   Rel#  Description of change
    //     =============  ===  ====  ===============================================
    //     Jul 3, 2006   JJB  1.00  Original version
    //  Public Types / Classes          Type Description
    //  ========================     =============================================
    //     SystemInfoWindow
    package utilities.msglib;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    * TODO Enter description
    class SystemInfoWindow extends JDialog {
          * @param args
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        Test thisClass = new Test();
                        thisClass.setVisible(true);
                        SystemInfoWindow window = new SystemInfoWindow(thisClass);
                        window.setMessage("System shutdown in progress ... lot sof atatarte athis tis a sa logoint of tesxt it keeps going and going and going thsoreoiat afsjkjslakjs fshafhdskrjlkjsdfj");
                        window.setVisible(true);
         //     ------------------------  Inner Classes ---------------------
         static class Test extends JFrame {
              private JPanel jContentPane = null;
               * This is the default constructor
              public Test() {
                   super();
                   initialize();
               * This method initializes this
               * @return void
              private void initialize() {
                   this.setSize(300, 200);
                   this.setContentPane(getJContentPane());
                   this.setTitle("JFrame");
               * This method initializes jContentPane
               * @return javax.swing.JPanel
              private JPanel getJContentPane() {
                   if (jContentPane == null) {
                        jContentPane = new JPanel();
                        jContentPane.setLayout(new BorderLayout());
                   return jContentPane;
         //     ------------------------  Static Fields ---------------------
         private static final long serialVersionUID = -8602533190114692294L;
         //     ------------------------  Static Methods --------------------
         //     ------------------------  Public Fields ---------------------
         //     ------------------------  Non-Public Fields -----------------
         private JPanel jContentPane = null;
         private JTextPane textField = null;
         public SystemInfoWindow(JFrame frame) {
              super(frame);
              initialize();
              //setUndecorated(true);
              setLocationRelativeTo(frame);
              pack();
         //     ------------------------  Interface Implementations ---------
         //     ------------------------  Public Methods --------------------
         public void setMessage(String text){
              textField.setText(text);
              adjustSize();
         //     ------------------------  Non-Public Methods ----------------
         private void adjustSize(){
              Dimension oldSize = textField.getPreferredSize();
              textField.setPreferredSize(new Dimension(
                        oldSize.width, oldSize.height + 30));
              pack();
         //     ------------------------  Generated Code --------------------
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(300, 200);
              this.setModal(true);
              this.setContentPane(getJContentPane());
              this.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowOpened(java.awt.event.WindowEvent e) {
                        //setLocationRelativeTo(MsgLibGlobals.parent);
                        pack();
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(new BorderLayout());
                   jContentPane.setMaximumSize(new java.awt.Dimension(50,2147483647));
                   jContentPane.add(getTextField(), java.awt.BorderLayout.CENTER);
              return jContentPane;
          * This method initializes textField     
          * @return javax.swing.JTextPane     
         private JTextPane getTextField() {
              if (textField == null) {
                   textField = new JTextPane();
                   textField.setEditable(false);
                   textField.setMaximumSize(new java.awt.Dimension(20,2147483647));
              return textField;
    }Message was edited by:
    BaltimoreJohn

  • Creating Scrollable text frames in InDesign

    I've been trying to create scrollable text frames in InDesign CS6 and, for the life of me, cannot figure out how to do so for an interactive PDF. 
    I've done so for touchscreen devices before through DPS and the scrollable frame option, but I've never tried to do it for something non-touchscreen/mobile.  I don't even know if it's possible, but I am sending this to someone who may not have touchscreen access with touchscreen scroll functionality and I wouldn't want to risk a good portion of text to go unread because of a lack-of functionality.
    So, I guess my question is:  Is there a way to create a scrollable text field for an interactive PDF that could be scrolled through using a mouse or keyboard? 
    Thanks in advance!

    No. It's DPS only.

  • INTERACTIVE PDF QUESTION - Scrollable Text Area

    I am trying to do my resume in a interactive pdf and need more room than my page offers.
    Is there a way to make a interactive pdf with a text box in place that has hidden text that can be scrolled up or down to read.
    Basically make the text area look like a placed web page within the interactive pdf with scroll bars.
    Any help would be greatly appreciated.
    Thanks,
    Joe

    If you want the scrollable text in the interactive pdf, and you are using indesign to create it do like this
    Export to interactive pdf
    Open the pdf in Adobe livecycle Designer and create textbox where you want and remove the Limit Text checkbox
    Then Export it to the pdf
    I think it will solve your porblem

  • How to create a text Component With Certain Properties

    I need to create a text component with the following properties:
    Has Capability to be italic, right/left aligned, have different background / foreground colors, and most importantly, the ability to have a fixed width and a height that is set by the amount of text in it (ie line wrapping expands the field vertically).
    It should be a simple exercise, but I cannot seem to figure out how to do it.

    Here is the correct syntax :
    private static JEditorPane constructPane(String text, int normWidth, int normHeight, boolean rightAlign, boolean italic,boolean isWhite) {
              JEditorPane pane = new JEditorPane();
              pane.setEditable(false);
              pane.setContentType("text/html");
              pane.setText(
                   "<html><head></head><body>"
                   + (italic?"<i>":"")
                   + "<table><COLGROUP><COL width=\""+normWidth+"\"><THREAD><tr><td valign=\"top\" align="+(rightAlign?"\"right\"":"\"left\"")+">"
                   + text+"</td></tr></table>"
                   + (italic?"</i>":"")
                   + "</body></html>");
              pane.setSize(normWidth,normHeight);
              if(isWhite)
                   pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1,0,1,0,Color.WHITE),BorderFactory.createEmptyBorder(0,1,0,1)));
                   pane.setForeground(Color.WHITE);
              else {
                   pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1,0,1,0,Color.BLACK),BorderFactory.createEmptyBorder(0,1,0,1)));
                   pane.setForeground(Color.BLACK);
              return pane;
         }

  • Formatting HTML Text in Text component

    Hi all,
    I'm trying to render some Html text in a text component, I'm
    getting the HTML from within an xml document as such:
    <xml><htext><p><b>Testing HTML
    Text</b></p><p>Here's another
    line.</p></htext></xml>
    If I put that into a Text component with the htmlText=htext
    property, the line spacing is as expected, but it seems to add in a
    blank space character for every character of the html code. (E.g.
    "<b>Testing" adds 3 extra spaces before the word "Testing").
    Renders like (using - as space character):
    Testing HTML Text
    -Here's another line.
    If I use the condeseWhite=true property on the Text
    component, it fixes the extra space characters issue, but then
    stuffs the line spacing up, so <p> becomes rendered like a
    <br>.
    Renders like:
    Testing HTML Text
    Here's another line.
    Any thoughts, or help is much appreciated, thanks in advance.
    Oz
    P.S I was trying to avoid the obvious "br" tag which will
    make it work and render correctly....
    <p><b>Testing HTML Text</b></p>
    <br/><p>Here's another line.</p>

    no. use css.

  • Multi-state scrollable text frames

    I've created a multi-state object with 5 different articles the problem I seem to be having is after scrolling half way down on one and switching to another it remains half way down the scrollable frame. Is there a way to have it return to the top of each state when switching between the states ?

    Sorry for the misplacement,
    I'm making a portfolio and have 5 separate projects to display, I was hoping to display them on one page with 5 separate buttons allowing the viewer to switch between them seamlessly than to have them on 5 separate pages.
    I've got the desired effect thus far using 5 scrollable text frames combined into one multi-state object but switching between states keeps it relative to where the person was in the last state. Due to some articles being smaller vertically than others this can be a problem as it shows up blank which will probably create an impression of the information being non existent or the program not working.
    I would appreciate any help on resetting the state to the upper left between changes and not just on the initial opening, or any alternative methods that would create the desired effect.

  • Output text component new line

    HI Team,
    I am picking up a value from resouce bundle for output text component.
    I wish to display data in output text component to display data after a new line.
    Suppose the message is coming as How are you.Welcome
    Now it should come as
    How are you
    Welcome
    Any help how is this achievable.
    I am working on Jdev 11.1.1.6
    Regards,
    Ajay

    Hi Team,
    The issue is resolved now.
    I have changed the escape property of output text component. to false so as to avoid the <br /> being HTML-escaped. and at the value level have used like
    <af:outputText value="#{XX.YOUR_REQUEST_HAS_BEEN_SUBMITTE}&lt;br />&lt;br />#{XX.YOUR_REQUEST_HAS_BEEN_SUBMITTE1}"
                                         id="ot10" escape="false"/>
    Where XX.YOUR_REQUEST_HAS_BEEN_SUBMITTE=Value1 and YOUR_REQUEST_HAS_BEEN_SUBMITTE1=Value2 in my resource bundle file.
    Output is coming as
    Value1
    Value2
    Does any one know how can i mark it as correct , can't see it after the forums upgrade to new one.
    Message was edited by: Ajay

  • Retrieve RowSet and Display in Output Text Component

    To retrieve a row object, took more effort than I expected with this tool. I wanted to populate a simple output text component with a db object pulled from a row, and I binded it to the rowset column. It worked great, but it kept retrieving the first row, since in the JSP it was calling this:
    #{questionsetup.questionRowSet.currentRow['question']}
    To get it to increment rows per output text component I did this:
    questionRowSet.setDataSourceName("java:comp/env/jdbc/SelfService");
            questionRowSet.setCommand("SELECT ALL dbo.Question.quesId, dbo.Question.question, dbo.Question.lastChangeDate  FROM dbo.Question");
            questionRowSet.execute();
            questionRowSet.next();
            outputText3.setValue(questionRowSet.getString("question"));
            questionRowSet.next();
            outputText4.setValue(questionRowSet.getString("question"));
            questionRowSet.next();
            outputText5.setValue(questionRowSet.getString("question"));Is there another way to do this automatically? The Studio Creator way? Or is this correct? The Studio Creator help file explains how to bind a simple component, and using the binding, but it even says it will retrieve the data in the first row. Incremenet rows or specifying a specific one would really help!
    Thank you very much!

    Maybe take control of the Select statement myself...
    So I decided to get the MIN value of my ID
    like this
    "select MIN(T21id) AS ttt from persons"
    now this is valid in SQLyog
    BUT Creator says
    Description: An unhandled exception ...
    Exception Details: javax.faces.el.PropertyNotFoundException
    Invalid column name: BaseRemuneration
    nb why is this "unhandled" since it is inside a try block?
    why does it mention BaseRemuneration which is a completely different but valid column??
    So Sun Creator will accept an unknown subset of valid SQL commands, and give bizarre irrelevant exception error messages on the set of valid SQL statements that it doesnt like.
    The documents appear to state that MIN is not handled by the IDE but can be entered manually.
    In fact it can NOT be enmtered manually.
    So is there an accurate list of valid SQL that is accepted?

  • Line highlighting in Text Component

    I'm trying to figure out how to apply a colored background to certain lines of a text component. This is common, for instance, in a lot of editors, especially IDE's (notably, Eclipse), where the currently selected line has a separate background color from the rest of the page. I'm having a lot of trouble understanding how to use Elements and Views and EditorKits and all that, and I'm not even sure if that will solve the problem. All I've been able to do so far is put a colored background behind individual characters; but then it stops at the end of the line, instead of continuing for the width of the text component.
    Any help is greatly appreciated.

    I assumed you were using the built-in Highlighter classes to do the coloring. If you aren't, you're doing a lot more work than you need to. Here's what I use:import java.awt.Color;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import javax.swing.text.*;
    * Usage: new CurrentLineHighlighter(myColor).install(myTextComponent);
    public class CurrentLineHighlighter implements ChangeListener
      static final Color DEFAULT_COLOR = new Color(0, 0, 0, 15);
      private Highlighter.HighlightPainter painter;
      private Object highlight;
      private JTextComponent comp;
      public CurrentLineHighlighter()
        this(null);
      public CurrentLineHighlighter(Color highlightColor)
        Color c = highlightColor != null ? highlightColor : DEFAULT_COLOR;
        painter = new DefaultHighlighter.DefaultHighlightPainter(c);
      public void install(JTextComponent tc)
        comp = tc;
        comp.getCaret().addChangeListener(this);
      public void stateChanged(ChangeEvent evt)
        if (highlight != null)
          comp.getHighlighter().removeHighlight(highlight);
          highlight = null;
        int pos = comp.getCaretPosition();
        Element elem = Utilities.getParagraphElement(comp, pos);
        int start = elem.getStartOffset();
        int end = elem.getEndOffset();
        try
          highlight = comp.getHighlighter().addHighlight(start, end, painter);
        catch (BadLocationException ex)
          ex.printStackTrace();
    }

Maybe you are looking for

  • Background Job Sheduling

    Hi, How to define a background jobs in Sm37. Give me the steps. Rgds, Shradha

  • How can I remove all JavaScript content from a form created in Adobe LiveCycle ES?

    Dear all, I have created a form from scratch (blank A4) that doesn't have any events with scripts. Nevertheless I still get the usual error message in Adobe Reader where we have disabled JavaScript: In Acrobat Pro 9 I can see 3 document level scripts

  • ISO 6.1.3

    Yeasteday i updated my IPhone 4s with the softweareISO 6.1.3 ever since then my phone has been unpredictable. My battery persentage says 60% but it constantly switches itself off then it says 1% then junps up to 65% and it seems to be lagging a lot a

  • How to put restriction/variable in BI 7.0 ? Is there any settings required?

    Hello, I am working on BI 7. I want to know ""How to put restriction/variable in BI 7.0 ? Is there any settings required? I am putting some variables in BI 7.0 while making some query"" amit shetye.

  • GR value field for a/c assigned PO

    Dear Gurus, How to know the GR value for the a/c assigned PO. In other words, Is it possible to know the GR value from any table without any manipulation.Thanks in advance. Cheers!