Controlling multiple TextAreas with one ScrollBar

Hello,
Fairly new to java so you may have to excuse my lack of java knowledge!
I would like to create a Frame with three TextAreas, side-by-side, controlled by a single ScrollBar.
I thought it would be fairly easy. Just add the three TextAreas to a Panel then add a ScrollPane to the Panel. If that is the right way, how can you make the TextArea as high as the number of rows. Think I've seen some example using Swing but I'm using AWT.
I've provided some example code if it helps:
import java.awt.*;
public class MyExample extends Frame
  TextArea field1 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
  TextArea field2 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
  TextArea field3 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
  MyExample()
    super("My Example");
    this.setSize(800, 500);
    new BorderLayout();
    //enter any data into all three text areas
    for (int i = 0; i < 150; i++)
      field1.append(i+"\n");
      field2.append(i+"\n");
      field3.append(i+"\n");
   /** Any method here to make the TextAreas the maximum height (so the TextAreas
   *   are too large for the Panel and need the scrollbar!). I have tried setSize,
   *   setMinimumSize, setMaximumSize, setRows and prob more but cannot get any
   *   to work!?!
    // create panel and add the three text areas
    Panel centerPanel = new Panel(new GridLayout(1,3));
    centerPanel.add(field1);
    centerPanel.add(field2);
    centerPanel.add(field3);
    //create a scroll pane and add the panel to control
    ScrollPane scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
    scrollPane.add(centerPanel);
    // add scroll pane to frame
    add("Center", scrollPane);
}Any help is appreciated!
Dave

Hai dave,
try the below program in which i set the panel size by calculating the textarea size. To caluculate the number of lines in the text area-field1:
1. store the value of field1 in a string
2. find the number of '\n' -end line characters
this gives the number of lines in the text area-field1
then set the height of the panel equivalent to the height of field1 by using the calculated number of lines * 15( a single line takes 15"-i am not certain but it is OK).
import java.awt.*;
public class MyExample extends Frame
TextArea field1 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
TextArea field2 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
TextArea field3 = new TextArea("", 0, 0, TextArea.SCROLLBARS_NONE);
public MyExample()
super("My Example");
this.setSize(800, 500);
new BorderLayout();
//enter any data into all three text areas
for (int i = 0; i < 300; i++)
field1.append(i+"\n");
field2.append(i+"\n");
field3.append(i+"\n");
/** Any method here to make the TextAreas the maximum height (so the TextAreas
* are too large for the Panel and need the scrollbar!). I have tried setSize,
* setMinimumSize, setMaximumSize, setRows and prob more but cannot get any
* to work!?!
**/int k=0;
String str=field1.getText();
/*my for loop to calculate number of lines in the string which holds value of TextArea-field1*/
for(int j=0;j<str.length();j++){
     if(str.charAt(j)=='\n')k++;
System.out.println(String.valueOf(k));
Panel centerPanel = new Panel(new GridLayout(1,3));
centerPanel.add(field1);
centerPanel.add(field2);
centerPanel.add(field3);
Dimension dim=field1.getPreferredSize();
ScrollPane scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
scrollPane.add(centerPanel);
//the scroll bar of mouse can't work!(?)
centerPanel.setPreferredSize(new Dimension(780,k*15));
add("Center", scrollPane);
setVisible(true);
public static void main(String args[]){
     new MyExample();
* if you still have problem then post but expects my reply after atleast 2 days:i am busy

Similar Messages

  • Controlling multiple videos with one set of controls

    I'm currently working on a project that allows the user to view multiple videos at one time. The videos will be exactly the same length and video format/type. I'd like to let the user use just one set of controls to view each video. Is this possible? If so, does anyone have any code samples?
    I also want the video to not start when the application starts. I've got that done, but I'd also like the first panel of the video to be displayed. How can I do that?
    Thanks!

    PS, I'd also prefer for the controls to be detatched from any of the viewers, if possible. Thanks!

  • Controlling multiple instruments with one VI

    I have 5 instruments that I need to control simutaneously.  Right now, each is controlled separately by its own VI, all of which run in LabVIEW 7.1.  I would like to consolidate control into one panel instead of 5.  I have seen examples of libraries that contain multiple sub-VIs controlled by a main VI, but I cannot figure out how data is passed between them, or how to create a library from my existing VIs.  Is there a way to do this? 

    For a simplistic answer, you just have to place your existing VIs into a new top level main VI. In order to pass data from a subVI to a mian, you wire the controls/indicators on the subVI to the subVI's connector pane. These is really basic LabVIEw knowledge and if you don't know how to do this, then you should probably spend some time learning LabVIEW basics. A great starting point is at http://www.ni.com/academic/lv_training/how_learn_lv.htm.
    With 7.1, a library is an llb file and you really don't need to use one of these. They can be handy for distributing an application but should not be used during development. Just keep your VIs in folders.

  • Controlling multiple movies with one button

    Hi flash gurus,
    I have 4 movies of the same length running on my stage in the
    FLV playback component, with different instance names. I also have
    a single play/pause component. I want all of the movies to play
    together and unpause/pause when I press the play/pause button.
    However, I have only been able to get the play/pause button to
    control one of the movies (the last one listed in the
    actionscript). I'm using the following code to attach the
    play/pause component to the FLV playback movie:
    FLV_instance_name1.playPauseButton = PlayPause_instance_name
    FLV_instance_name2.playPauseButton = PlayPause_instance_name
    FLV_instance_name3.playPauseButton = PlayPause_instance_name
    FLV_instance_name4.playPauseButton = PlayPause_instance_name
    When I use this, the play/pause button only controls the
    FLV_instance_name4 movie. How do I get it to control all 4 moives?
    Any help is much appreciated. Thanks!

    PS, I'd also prefer for the controls to be detatched from any of the viewers, if possible. Thanks!

  • Create multiple folders with one click on documents tab in BP in SAP CRM

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

  • Multiple iPhones with one one computer

    I was using multiple iPhones with one one computer, each iPhone device has it's Owen Apple ID. When I connected my device. I got my mothers photos, contacts &amp; applications. All my applications are deleted, is there a way to retrieve my iPhones photos and applications ?

    Sign out of your mom's account in itunes, then sign in with your account, then restore your phone from your itunes backup.

  • Multiple selections to multiple layers or multiple files with one go ?

    Hi,
    how to convert multiple selections to multiple layers or multiple files with one go ?
    Thanks!

    You may want to ask over at
    http://forums.adobe.com/community/photoshop/photoshop_scripting?view=discussions
    or
    http://ps-scripts.com/bb/
    I think there are Scripts about for the task or at least ones that could be adapted without too much problems.
    The usual approach is, I think, creating a Work Path from a Selection and then using (expanded) Selections based on the individual subPathItems to intersect with the original selection.
    Of course there are possibilities for bad results …

  • Photoshop crashes while using multiple windows with one image

    Has anyone else encountered the following problem:
    Photoshop CS4 crashes sooner or later when working with multiple windows with one image (window->arrange->new window for...).
    I remember having same problem since CS2. Is this a bug in Photoshop or am I having a bad luck?
    Technical specifics:
    Ps CS4, iMac, 21.5, 10.6

    Don't know.  I haven't heard of other people having that problem.
    Do you have a crash report I could look at?
    Or have you attached your email to crash reports sent to Adobe and can you tell me the date on one of them?

  • Create multiple delivery with one invoice

    Hi all,
    can you tell me how to do multiple delivery with one invoice,
    i tried in vf01 by giving their my 3 delivery nos but it is generating three invoices
    pls explain this in details
    points will be rewarded
    regards,
    smmmmmm

    Dear Sameer
    As per your requirement run the Tcode VF04 (Billing Due list) and select the Delivery Documents for which you want to to have single Billing Document by clicking on Collective Billing document/Online  Push Button in that screen.
    To Have Single Billing Document for Multiple Delivery you need to have Payer,Terms of Payment,Incoterms(part 1 and part2) same for all materials orelse the billing document will split and this split analysis is visible during creating of Billing document.
    Hope this will help you in solving your problem.
    Regards
    PSH

  • Select or deselect multiple rows with one single selection  event

    Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
    row1
    row2
    row3
    row4
    row5
    row6
    What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
    For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
    Hopefully someone can give me a hint.

    Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
         private void addLineToList() {
              String a = f_one.getText();
              String b = f_two.getText();
              if (a.length() == 0) {
                   Utils.showInformationMessage("Item field is empty.");
                   f_one.requestFocusInWindow();
                   return;
              if (b.length() == 0) {
                   Utils.showInformationMessage("Match field is empty.");
                   f_two.requestFocusInWindow();
                   return;
              model.addElement("item: " + a);
              model.addElement("match: " + b);
              model.addElement(" ");
              int size = model.getSize();
              pairList.setSelectedIndex(size - 3);
              f_one.setText("");
              f_two.setText("");
              f_one.requestFocusInWindow();
         private void editList() {
              if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
                   Toolkit.getDefaultToolkit().beep();
                   f_one.requestFocusInWindow();
                   return;
              if (!f_one.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Item field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   OptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              if (!f_two.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Match field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   JOptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              String item = "";
              String match = "";
              int index = pairList.getSelectedIndex();
              String choice = model.getElementAt(index).toString();
              if (choice.startsWith("item")) {
                   item = choice;
                   match = model.getElementAt(index + 1).toString();
                   model.remove(index);
                   model.remove(index);
                   model.remove(index);
              else {
                   item = model.getElementAt(index - 1).toString();
                   match = choice;
                   model.remove(index + 1);
                   model.remove(index);
                   model.remove(index - 1);
              int size = model.getSize();
              if (size > 2) {
                   pairList.setSelectedIndex(size - 2);
              f_one.setText(item.substring(6));
              f_two.setText(match.substring(7));
              f_one.requestFocusInWindow();
         }

  • How do I create multiple TEBs with one submit button on one page in Captivate 7

    I've read other posts on this topic (which refer primarily to earlier versions of Captivate) and am still at a loss as to how to put multiple text entry boxes on a page with one submit button. Here's my scenario:
    I am creating test questions.
    Each test question has multiple text entry boxes (for numbers only).
    Student should be able to enter numbers into the textboxes in any order.
    Then there is one Submit button that should initiate validating all the text entries, and move to a scoring page (so I can test it). (What would be best is if this button not only did the above, but also submitted scores to the LMS.  But that is not my question at this time.)
    I'd like this question to be set up as a template so that I can duplicate it, be able to add or delete text boxes and change the values required in the text boxes.  
    Here is an image of a sample question page with multiple TEBs. The yellow boxes tell the student where they need to enter text:
    Any help or direction to help is appreciated!!

    I think the problem here is that Arlhoolie wants all of the different TEBs to behave as if they were part of a single interaction that submits only ONE result to the quiz.  Using multiple TEBs in Captivate means that you have multiple scored objects and therefore multiple results being submitted to the quiz.
    If you want a single Success or Failure result submitted to the quiz based on the results from multiple interactive objects then there really is no simple way to do it.  But you could try using the Infosemantics Interactive Master widget to combine all the TEBs as slave objects that report to the Master Widget, which then reports a single score to the quiz based on the results from the slave objects.
    You can learn more about the Master widget here:
    http://www.infosemantics.com.au/adobe-captivate-widgets/interactive-master
    http://www.infosemantics.com.au/interactivemaster/help
    You can download a free trial version of the widget here:
    http://www.infosemantics.com.au/adobe-captivate-widgets/download-free-trial-widgets
    One caveat you should be aware of is that this widget is not HTML5 compatible.

  • Multiple tasks with one click

    My work involves manually changing multiple lines to a different graphic style, and then moving that line to a different layer.  As it is now, I am changing the graphic styles, choosing Select < Same < Fill & Stroke, and then moving the lines to the appropriate layer.  I am wanting to know if there is a way to change the graphic style, and move the line to the different layer with one click.  I'm ignorant when it comes to scripting, but was wondering if there are any scripts that would perform this function.

    You need to fully explain the setup. Otherwise, people making suggestions are just guessing. Here's my suggestion, based on what little information you have provided:
    You don't need a script for this; you can do it with a set of very simple Actions. Example:
    Assume your repetitive task requires three Layers, named Red, Green, and Blue. On each Layer, all objects need to have the same Graphic Style applied.
    1. New document. Create three Layers. Name them Red, Green, and Blue.
    2. Define three Graphic Styles. Name them Red, Green, and Blue.
    3. Draw an object (any object; a square, a line, whatever). Send it to Layer Red. In the Attributes Palette, type "Red" into its Note field. (This effectively "names" the object "Red".
    4. Draw an object, Send it to Layer Green. Type "Green" in its Note.
    5. Draw an object. Send it to Layer Blue. Type "Blue" in its Note.
    6. Draw an object on Layer Red. Select it.
    7. Actions Palette: New Action. Name the Action "Red." Set its color to red. Start recording:
    7.1 Edit>Cut
    7.2 Edit>PasteInFront
    7.3 Apply Graphic Style Red
    7.4 Stop recording.
    8 Actions Palette: Select the Cut step. From the flyout menu select Select Object.... In the resulting dialog, enter "Red". OK the dialog. The Action should now have a new Set Selection step listed after the Cut step.
    9. Actions Palette flyout menu: Button Mode.
    Now you have an Action named Red that appears as a red button in the Actions palette. Select an object. Click the button. The object is moved to Layer Red, and gets Graphic Style Red.
    10. Turn off Button Mode. Duplicate the Action. DoubleClick the duplicate. Change its name to Green and its color to green. Edit its Set Selection step to select the object named Green. Replace its Graphic Style step with a step that applies Graphic Style Green.
    11. Similarly duplicate and edit one of the two Actions to create a Blue Action. Put the Actions palette back in Button Mode.
    Now you can select any number of objects, and then move them to the Red, Green, or Blue Layer and apply the appropriate Graphic Style wiht one click.
    Now come back and reveal the specifics of your actual situation which renders all that work moot.
    JET

  • HT1495 syncing multiple ipads with one master ipad

    Does anyone have any advice on getting multiple ipads (aprox 10) to sync with one master ipad?

    Without connecting the iPad to your computer ...... Launch iTunes and go to Edit>Preferences>Devices. Turn off auto sync by clicking on the box at the bottom that says ..... Prevent iPods, iPhones ...etc. Click OK. Quit iTunes
    Connect the master iPad to the computer and launch iTunes.
    Transfer any purchases from the master iPad into iTunes via File>Transfer purchases from the menu at the top of iTunes or right click on the iPad name under the devices heading and select Transfer Purchases. Let the process complete.
    Next .... right click on the iPad name on the left side of the iTunes window under the devices heading and select - Backup. Let the backup process computer. Then sync with iTunes  and eject the iPad
    Connect the next iPad and right click on the iPad name under the devices heading and select - Restore from backup. Select the backup of the first iPad and let the process complete and then sync with iTunes. Eject the iPad.
    Connect the next iPad and follow the same procedure and do the same with the rest of the devices.

  • How to iMessage between multiple devises with one apple id

    We have 2 iPhone 4S an iPad 2 and a iPod touch. How can I use imessage for all the devices with one apple id

    Try this complete previus discussion:
    Re: iMessage between iPhone, iPod, iPad under same Apple ID

  • Multiple emails with one itune account

    My husband has an iPhone and I both iPod with one itune account.
    How can we keep out personal settings and information seperate on the cloud?

    Yes, there is a way to use the new apple id with iMessage.  First, go into your settings on your iOS device and click on Messages.  Then, click on recieve at in the messages settings.  You can then click on your apple id at the top and signout.  After, log into your new account.  Your other option is to click add another email and enter your new email for iCloud.

Maybe you are looking for

  • Problem when creating receiver agreement for File to IDOC scenario

    I have done the following : 1. Created two business systems one for the file system and other for the R3 system and also I created two communication channel, one as sender communication channel and one as receiver communication channel. 2. Created th

  • Number formatting in ALV list header

    Hi, I am using an ALV with a list header. Code is as follows: FORM ALV_SHOW.    DATA G_CALLBACK_PROG LIKE SY-REPID.    G_CALLBACK_PROG = SY-REPID.    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'       EXPORTING          I_CALLBACK_PROGRAM      = G_CALLBACK

  • Email only get a blue box with  question mark

    would someone tell me how to fix my problem, when I get emails and adds I only get a blue box with a question mark. The rest of the family gets the complete email. The older version worked with no problems.

  • Unable to bring up reporting services, getting following error

    <ApplicationArchitecture>AMD64</ApplicationArchitecture> rshost!rshost!1c0c!03/10/2015-01:08:12:: i INFO: CLR runtime is initialized. rshost!rshost!1c0c!03/10/2015-01:08:12:: i INFO: Derived memory configuration based on physical memory as 33553912 K

  • ShowModalDialog - session lost

    Hi All, Using showModalDialog to open a pop up window the session value getting lost. How to resolve this? window.showModalDialog(url,"","resizable:no;help:no;dialogHeight:17;dialogWidth:14")- vignesh