Easy question about JScrollPane issue

The problem is I do not understand why it is not possible, or what I am doing wrong to not be able to initialize a JScrollPane with a variable and call it later, real easy to see in the code below.
NOTE! I CAN use scrollbars, but only without initializing first, am just trying to understand how to properly do this with initialization or if it is not possible.
Thank you!!!!
just look for the First 3 commented sections with stars ******
import java.awt.Container;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class SquareIntegers extends JApplet {
     // set up GUI and calculate squares of integers from 1 to 10
     public void init() ///all variables below are LOCAL, because used only in "init()" if needed elsewhere make above in the CLASS
                         //OR SAVE VALUES between calls to the class's methods
            // get applet's content pane (GUI component display area)
          Container container = getContentPane();
          container.setLayout(new FlowLayout());
          //creaing a layout because I wanted to add a scroll pane
          //container.setLayout(new BorderLayout());
          // JTextArea to display results
          JTextArea outputArea = new JTextArea(8, 8);
          // JScrollPane myscrollbar = new JScrollPane( outputArea ); //********************this is line 27 why does this along with line 33 NOT work????????
          // attach outputArea to container
          container.add( outputArea);
          //container.add( myscrollbar); ******************************this is Line 33 why does this along with line 277 NOT work????????
          container.add(new JScrollPane( outputArea ));//***********this is Line 34, if I comment out 27/33, and just use this, scrollbars
                                                                 // work correctly, but I have heard/seems better to "initialize variables first"
          int result; // store result of call to method square
          String output = ""; // String containing results
          // loop 10 times
               for ( int counter = 1; counter <= 10; counter++ ) {
               // calculate square of counter and store in result
               result = square( counter );           //***********************uses the CUSTOM method from line 44
               // append result to String output
               output += "The square of " + counter +
               " is " + result + "\n";
               } // end for structure
     outputArea.setText( output ); // place results in JTextArea
} // end method init
     // square method definition...***** This is a CUSTOM method creation..... if "Math.sqrt" was used, we would not have to do this
     public int square( int y )
     return y * y;      // return square of y this is RETURNED to the statement in "init()" that originally invoked the
                         // "square()" method - in this case line 32, where RESULT invoked the METHOD, so "result" gets the value of RETURN
                         // if it were "public int square()" that means the method does NOT return a value
The general format of a method definition is
return-value-type method-name( parameter-list )
declarations and statements
including "return;" or "return EXPRESSION;"
     } // end method square ALL METHODS must always be created inside the CLASS definition, as this one is... notice the closing
          // CLASS bracket below
} // end class SquareIntegers

Thank you!!!
I think I understand...... since the JScrollPane already assigned itself to the JTextArea....
when "adding" to the parent container, the only necessary component to call was in fact the JScrollPane with the container.add( myscrollbar); I do not know if this is correct, but I thank you for your help, because this definitely confused me, back to studying :)
I have it 100% operational, just posting this to say thank you that it worked, and it will help further my and possibly others understanding of this.

Similar Messages

  • Easy question about Reformatting

    Hello all,
    I am trying to reformat my HD after I have deleted Windows XP off of a partition. The reason for this is an upgrade to Vista and a larger allotment of HD space. My question is:
    I am using Backup v3.1.1. (v369) and I have FULL backup files of my Home folder, and my Music folder (as backup for my backup) for all my iTunes libraries. These are located on a portable HD. Are these the correct files to have backed up in order to have my MAC the way it was before I started the process? If so, then once the reformatting is complete, how do I get it all back onto my MAC permanently? Will all my apps and tweaks work as before?
    I am sure this is a simple question, however, I have never had to do this with a MAC, and I want to make sure I have all bases covered before I begin this. Any other comments or advice would be greatly appreciated.
    Thanks All!

    You call this an easy question ???
    Just messin with ya
    Your home folder is the most important folder containing your music, documents, preferences etc. but a lot is also stored in the system folder and library folder outside your home folder, if you want to be ensured of an exact copy of your current system the best way to go at this is to clone your system partition.
    The app i use for this is carbonCopyCloner
    http://www.bombich.com/software/ccc.html
    To add to this.. i've heard there is software for the mac that allows you to make adjustments to the size of your partitions without having to format the drive, i don't know the names of these products but i do know that it's very risky to use them, if you decide to use an app like that make sure you have proper backups of everything just in case it goes wrong.
    Message was edited by: Pr0digy V.

  • A few questions about common "issues" before buying New iPad

    I am hoping to pick up the new iPad in the next few weeks, however I have read up on some issues which I'd like some information on.
    I have been using my GF's iPad 2 a lot and I really love it, however I am dead set on buying the new one, I have become pretty resolution-spoilt by the awesome screen on the 4S and this is the primary factor in wanting this new model.
    With the following concerns, assuming that an iPad that I may buy might have one or more of them, could you please inform me of: any currently known official or unofficial fix, if the problem could most likely be resolved in an update or if it is likely that since the problem came to light that the later runs to be built were adjusted to avoid the problem? Thanks.
    OK- first up, the bad wifi problem that people have. This is the biggest concern to me, as I use wifi a lot and won't have access to 4G, and only occasionaly access to 3G.
    Secondly, the heating... OK this is not a deal breaker, I understand that it isn't a real problem however if it could be solved so that it runs almost as cool as the 2 that would be great.
    Thirdly, charge times and the extra hour over 100%... Again I do realise that these aren't so much issues as just the way that it works, however I would hope that now lots of people have complained, an update would adjust the display to be more accurate, to say 100% only when it has fully charged, purely because I would rather know... Or perhaps have 100% change colour on absolute 100%. The other thing, 7 hours charging, is there a more powerful adaptor that 1: reduces the charge time, and 2: if you are using a powerdrinking app while charging, will actualy continue charging rather than just slowing the battery drain (I read that some apps will keep draining battery while on charge).
    finaly, I have read about screen hue problems, this wont be too much of a problem, as I will be able to check this in store to be sure that the screen is nice, colour balanced and free of dead pixels, I will compare it to my GFs iPad 2 and also the iPhone 4, because I know that the iPad 2 is supposed to look a little more blue to give it a cold feel, while the new model and the iPhone 4S have a slightly yellowed screen for warmth, it's just that lots of people have complained about theres' being too yellow.
    Thanks very much for any useful info on this.

    What are all the differences between the iPad 3rd Gen and the iPad 2? Is the iPad 2 worth the cost savings?
    http://everymac.com/systems/apple/ipad/ipad-faq/differences-between-ipad-3rd-gen -2012-ipad-2-2011.html
    What are all the differences between the iPad 3rd Gen models? Which should I buy?
    http://everymac.com/systems/apple/ipad/ipad-faq/differences-between-ipad-3rd-gen -early-2012-models.html
    Should I Buy a New iPad? Or an iPad 2?
    http://www.maclife.com/article/blogs/should_i_buy_new_ipad_or_ipad_2
    iPad Q&A
    http://www.everymac.com/systems/apple/ipad/ipad-faq/differences-between-ipad-3rd -gen-early-2012-models.html
    A Few Questions (and Answers) About the New iPad
    http://pogue.blogs.nytimes.com/2012/03/15/a-few-questions-and-answers-about-the-   new-ipad/?ref=personaltechemail&nl=technology&emc=edit_ct_20120315
    New iPad: A Polishing of the Old
    http://www.nytimes.com/2012/03/15/technology/personaltech/the-new-ipad-is-much-t he-same-only-better.html?nl=technology&emc=edit_ct_20120315
    iPad 1, 2 and New Specifications
    http://www.everymac.com/systems/apple/ipad/index-ipad-specs.html
    If you think you may get an iPad 2:
    Refurbished iPad Prices
    http://store.apple.com/us/browse/home/specialdeals/ipad
    New 16GB iPad 2 Prices
    http://store.apple.com/us/browse/home/shop_ipad/family/ipad/select_ipad2
    A lot of the posts about lack of charging is because iPad "3" users are trying to use an iPod charger, iPhone charger or connected to their computer where they get the "Not Charging" indication. A few others had a defective charger that was replaced by Apple. It remotely possible that a few iPads have defective batteries or charging circuits.
    Many of the wifi connection problems are related to the users brand of wireless routers, the router setup, or the need to select a different wireless channel due to interference.
    The high temp problem seems to be when users are charging AND running games with intensive graphics. The display on the new iPad takes a lot more power than the iPad 2 display.
    Overall I would guess that the chance of a defective iPad is less than 1%.
     Cheers, Tom

  • Easy Question about resizing video

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    In my old program "Premiere', to resize and move a video around was very easy. You could adjust the scale and X-Y values numerically, or you could use a Free Transform like in Photoshop. Simply dragging bounding boxes for size and aspect and also dragging the clip to decide it's location.
    The only way I know how to do this in FCP is I double click a clip in the sequence, it loads into the viewer, I go to the Motion Tab and then I can adjust the Scale, which is cool. But then I'm left with the Distort section to adjust position (and aspect if need be). In the Distort section there are 8 numeric fields of info to figure out and fill out just to get one clip in a different position correctly.
    I'm thinking there must be another way to adjust the location (or aspect) of a video clip without spending a bit of time on exact coordinates, I want to eye-ball where I want the clip to go and simply move it there. Is the Distort feature the only way to do this? If not, which is the fastest way to move and change the dimension of a clip.
    Thanks for reading, I hope there is another way, I'm not use to these calculations and they're slowing me down.
    Monty

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    That's because it's not a simple question at all and yet every one of those threads was related to the OP's question. As you discovered, there are lots of ways to interpret "resize," during capture, editing, effects, output, viewing, encoding, printing. But the solution was even simpler than you thought. All you had to do was open the manual or the online help system. Start taking the manuals to the gym with you. FCP is not Premiere. You're going to hate FCP, you're going to love FCP but it will never behave like Premiere beyond the elements of the functional paradigm. Forget Premiere.
    bogiesan

  • Question about security issues regarding 'cp' and 'mv'

    Ok, I wondered about how 'cp' and 'mv' are really working. I have some guesses but I need these things to be confirmed.
    Here is what I have:
    A partition with a unix file system, say ext2 or 3 (does this make a difference here?) containing *very* sensitive data. The filesystem is encrypted (whirlpool/serpent) but that shouldn't matter. As I do not want corpses of dead files lying around that could be recovered, I always use 'shred -zu' with 26 passes to overwrite and then delete the data.
    And that's where I have my conceirns:
    If I want to rename a file or move it to another folder on the same partition. Is it save to 'mv' it? Or should I 'cp' it and then 'shred' the original file. I assume that 'mv' will not touch the actual file and just tell the file system of it's new name or place in the folder-structure. Given that, shredding a 'mv'ed file should not leave a trace of it on the drive (except of the old filename before the 'mv' maybe, but that wouldn't be too critical). I assume that, because it's the only thing that would make sense to me, but have to know it for sure!
    However, on moving the file to another drive I should probably 'cp' it, then 'shred' the original file. The question I have here is as follows:
    How much information which could be recovered leaves 'cp'ing in my RAM? Will I have to find a way to somehow shred the information in the RAM or can I assume that my RAM get's rewritten often enough, that most traces will be gone, say, in a couple of days?
    If you have links at hand to confirm your answer, please post them, too.

    Okay, thanks for that, I will have a closer look on flushing the ram.
    Sure, I care about security and privacy, but -- as you might expect -- the data I have are not really THAT sensitive/confidential/whatsoever. I've just gotten into it somehow and now I'm just curious/intrested in improving it for it's own sake more or less.

  • Question about JScrollPane

    Hi everybody,
    I'm using HSQLDB in my program and users can execute custom queries with a JTextArea. When an exception is thrown during the excecution of a big query, the message is pretty large, because it contains the query itself and the warnings/remarks about it.
    What I wanted to do was to use a JOptionPane and add the message to the JOptionPane inside a JScrollPane. I want the maximum size of the JScrollPane to be 320 x 160. This is what I'm doing now:
    Dimension size = new Dimension(320, 160);
    JLabel label = new JLabel(exception.getMessage());
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.getViewport().setLayout(new FlowLayout(0, 0, FlowLayout.LEFT));
    scrollPane.getViewport().add(label);
    scrollPane.getViewport().setMinimumSize(size);
    scrollPane.getViewport().setMaximumSize(size);
    scrollPane.getViewport().setPreferredSize(size);
    scrollPane.getViewport().setSize(size);
    scrollPane.getViewport().setBackground(Color.WHITE);
    JOptionPane.showMessageDialog(null, scrollPane, "Error", JOptionPane.ERROR_MESSAGE);I want no horizontal scrollbar, only a vertical. The problem with the code above is that the message stands on one line, instead to be spread on more then one line (thereby, you cannot see the message completely, because the horizontal scrollbar is disabled).
    The result I want is that the message is spread over more then one line, like in HTML when you've got a long text, the browser itself will spread the text over several lines that are available in the container where the text is in.
    Does somebody understand my problem? :-) I wish I could upload an image as an example, but FTP is blocked on the network where I'm connected to.
    Kind regards,
    Sweepee.
    Message was edited by:
    Sweepee

    see if this gets you close
    import java.awt.*;
    import javax.swing.*;
    class Testing
      public static void main(String[] args)
        JTextArea ta = new JTextArea();
        ta.setLineWrap(true);
        ta.setWrapStyleWord(true);
        ta.setText("I want no horizontal scrollbar, only a vertical. The problem with the"+
        " code above is that the message stands on one line, instead to be spread on more"+
        " then one line (thereby, you cannot see the message completely, because the"+
        " horizontal scrollbar is disabled).\n\nThe result I want is that the message is"+
        " spread over more then one line, like in HTML when you've got a long text, the"+
        " browser itself will spread the text over several lines that are available in the"+
        " container where the text is in.\n\nDoes somebody understand my problem? :-) I wish"+
        " I could upload an image as an example, but FTP is blocked on the network where I'm connected to.");
        JScrollPane scrollPane = new JScrollPane(ta);
        scrollPane.setPreferredSize(new Dimension(320, 160));
        JOptionPane.showMessageDialog(null, scrollPane, "Error", JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }

  • Quick (hopefully easy) question about rotating video...

    I'm going to be shooting some video soon that I will later be editing with FCP. I'm going to shoot the video on a Canon Vixia HF10 (AVCHD) camcorder.
    In the situation I'll be shooting, with the mount I'll be using, it would be much easier for me to shoot this video with the camera fully upside-down.
    If I shoot the video fully upside down, can I easily rotate it 180 degrees in FCP with no loss of quality?
    Thanks!

    An interesting thing about video that is shot upside down is the ballistics of the camera movement can be weirdly disconcerting. For instance, if it's a helmet- or wing-style mount, pans and tilts just feel odd.
    As Eric suggests, flipping the image 180 degrees is easy but practice and evaluate.
    bogiesan

  • Quick Easy Question About N580GTX-M2D15D5 Bios

    Hey guys!!
    I just have a real quick and easy (i suppose) question!
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly since the bios date and version remained the same?
    Thanks !

    Quote
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    Quote
    version 70.10.17.00.01
    that's suppose to be, this is the version of the both bioses
    Quote
    & date November 09, 2010
    this is GPU release date, not BIOS date
    Quote
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly
    Get this: https://forum-en.msi.com/index.php?action=dlattach;topic=147603.0;attach=7931
    extract it somewhere, then run info1 , and look for the last line
    Quote
    since the bios date and version remained the same?
    they are not the same, your looking the wrong stuffs

  • Really easy question about DVDs

    I am about to get a new 5g iPod, and I am excited about being able to watch videos on it. But I have a quick question, is it possible to rip DVDs(like you can with CDs) from iTunes?
    Thanks

    This article addresses your question:
    http://docs.info.apple.com/article.html?artnum=302758

  • Question about security issue when transferring files from PC

    I am in the process of looking at macs. I have always been a PC user and have been EXTREMELY impressed with the features of mac os x. Here's the question. I am probably sure that I have one or more viruses on my PC, what PC doesn't right? When I get my mac, I'm looking at the macbook, I see that I can transfer my files over from a PC to my new mac. The problem is. I want my files, but I'm leery about transferring a virus over also. I've heard about the security of macs and I am wondering if this is something I need to be worried about, or if it won't be a problem. Is there any steps I will need to take to ensure that I don't bring any viruses over with my files? Thanks for the help.
    Micah
    P.S. I am really starting to get sick and tired of Vista. I had to download VLC media player to play my Windows Media files because my Windows Media player on Vista WILL NOT play the files meant for that system. Arrrghhh Sorry for the vent.

    Be sure to scan all your files for viruses before moving them from the PC to the Mac. Although PC viruses should have no effect on a Mac, it's still possible to pass on a virus to a friend via email.
    Do You Need Anti-Virus Protection for Your Mac?
    According to Rich Mogull's article, Should Mac Users Run Antivirus Software?,
    "The reality is that today the Mac platform is relatively safe. There are hundreds of thousands of viruses and other malicious software programs floating around for Windows, but less than 200 are known to target the Mac, and many of those are aimed at versions of the Mac OS prior to Mac OS X (and thus have no effect on a modern Mac).
    It's not that Mac OS X is inherently more secure against viruses than current versions of Windows (although it was clearly more secure than Windows prior to XP SP2); the numerous vulnerabilities reported and patched in recent years are just as exploitable as their Windows equivalents. But most security experts agree that malicious software these days is driven by financial incentives, and it's far more profitable to target the most dominant platform."
    Mr. Mogull is a computer security expert. I recommend reading the entire article as it is quite informative.
    For additional information on viruses, trojans, and spyware visit The XLab FAQs and read the FAQs on viruses and spyware.

  • Questions about different issues on a Satellite A30

    Ok, to start, I don't know much about computers let alone laptops but my husband is "usually" good with them but right now we are having major problems.
    I have a Satellite A30 (not sure if it's a pro as it doesn't mention it in the manual and Stephen is about to have a heart attack right now and isn't on the laptop so can't check the BIOS).
    Anyway. Problems started quite some time ago, in fact not long after the warranty ran out. I bought it second hand and I loved it when I got it.
    Ok
    Problem 1. - Overheating, we finally solved that by hoovering it out every now and then, problem solved.
    Problem 2. - USB 2.0. Some things work some don't. My Nikon camera won't work via USB but my Lumix does. My mobile struggles. Just bought a card reader, worked on Stephen's laptop but not the A30. Bluetooth dongle doesn't work. All these items used to work.
    Problem 3. - I can set my processor speed to either 1.6GHz or 3.06GHz. Overheats really easily on 3.06 and tends to slow down and seems to be faster on 1.6GHz and doesn't overheat on 1.6 so end up keeping it on that. Pain though. Even with extra under laptop fan cooler base.
    Problem 4. - Not that I'm an expert but I think my power supply is gone. I always have my laptop plugged in about 90% of the time. I can put the laptop on and it will use the AC Adaptor for a while then goes on to Battery Power. If the AC Adaptor was in that was what it used, not the battery. Then when the battery gets to the end of it's power it just goes and I have to wait until it charges again before I can turn it back on. I find that really annoying.
    Problem 5. - As from 2 days ago it has went totally and utterly kaput. Won't even log on. It goes as far as Windows XP booting up then an error message saying something about a missing .DLL file. Stephen said he sorted that but hasn't resolved the problem. We decided it was a hard drive problem so bought an external case for it and Stephen after 2 whole days managed to upload everything from the HDD to his laptop. It was a 40gig HDD. Some of the files were warped and had to be deleted so thought that was the problem so went out to buy a new one but went for a 120gig. Stephen formatted that on his laptop then went to transfer it to my A30 but same problems. Now I am wondering if 120Gig is too much. At the mo Stephen is taking out his HDD to put in mine and vice versa. His laptop is recognising it as a 120GHz but according to him my BIOS is not very clear and doesn't tell you anything. As I said I know nothing about computers. I'm really clutching at straws here. Stephen has been brought up on computers but is more used to desktops and we decided to sell our laptops and buy a high spec up to date desktop but I doubt I'd get much money now for my A30 if it doesn't work.
    Any ideas would be sooooo helpful to get it rolling again.
    Sorry for this thread to be so long but although Stephen won't admit to it, he really needs help and I can try and give any info you need to help us out.
    BTW I read in my manual that it can take up to 80Gig HDD but larger ones in the future so we thought it would be fine with 120 by now since they are available if that is any help to you.
    [Edited by: admin on 08-Jul-2007 08:29]

    Hi there,
    do you have still warranty on that machine? If yes then bring it TOMORROW to an authorized service partner.
    Why? The problem is that this machine has an Pentium 4 which really gets hot and if the cooling system is clobbed with dust, then the cooling paste which transfers the heat between cpu and cooling module gets dry and cannot transfer the heat accurately to the copper cooling module.
    I would suggest you to go to an technician and advise him to exchange the cooling paste, it will really raise your system stability.
    Believe me. :)
    The other thing with USB is: sometimes there is no enough power in the system and I assume that the problem lies on the AC-adapter. Purchase an new AC-adapter and you probably wont have problems with stability, USB and some other things anymore. I cannot tell it for sure, but I solved a problem with a Satellite 2430 which I had and which is quite the same model like yours, it has just some other colors but the model is the same.
    I had that heat problem and I solved it by exchanging the cooling paste, but then the machine was not in warranty anymore and I am a little bit familiar with computers.
    I had problems with my AC too, but my error was another because it mades some noise and after a while it stops working. At this time the system did not worked properly and after exchanging the AC everything was fine again.
    Regarding the HDD: I cannot tell you something about since I am using just a 60GB drive. You will probably find it our on your own or a experienced user here in the forum could maybe help you.
    I wish you good luck with your machine and a nice weekend
    Greets
    Dennis

  • Need help! easy question about scrollpane?

    DefaultStyledDocument document = new DefaultStyledDocument();
    JTextPane tp = new JTextPane(document);
    tp.setMargin(new Insets(5,5,5,5));
    JScrollPane tpScrollPane = new JScrollPane();
    tpScrollPane.setBounds(new Rectangle(5,5,100,200));
    tpScrollPane.getViewport().add(tp, null);
    the compile and run are both OK. but i found it quite strange that the vertical scroll bar works well while the horizental scroll bar doesn't work. when the string inputed up to the width, more inputted characters will be showed in a new line. Could anyone have the same experience and know how to solve it?
    any suggestions are appreciated!
    thanks in advance!

    have you tried it using
    tpScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS;

  • A question about JScrollPane

    Hello,
    I would like to create a Swing window that its size is (700,500) and it stores data that is recieved from user.
    The size of input from user is unknown, so I want that there'll be a scrollPane in axes X and Y.
    The problem: scrollPane doesn't fits to the data. How can I solve this?
    public void buildGUI(List<String> classList, Map<String, ClassData> classes)
         JFrame f = new JFrame("C");
         f.getContentPane().add(new JScrollPane(new GraphPanel(classList,classes)));
         f.setSize(700, 500);
         f.setLocationRelativeTo(null);
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.setVisible(true);
    class GraphPanel extends JPanel
    {     List<String> classList;
         Map<String, ClassData> classes;
         List<InfoRect> nodes;
         Map<InfoRect, String> edgesToBuild;
    public GraphPanel(List<String> classList, Map<String, ClassData> classes)
    { this.classList = classList;
         this.classes = classes;
         //     JLabel label = new JLabel("C");
    // label.setFont(new Font("Serif", Font.BOLD, 28));
    // label.setHorizontalAlignment(0);
         //add(label);
    //setPreferredSize(new Dimension(700,500));
         // super();
    setBackground(Color.WHITE);
    /* JLabel label = new JLabel("A label");
         label.setFont(new Font("Serif", Font.PLAIN, 14));
         label.setForeground(new Color(0xffffdd));
         add(label);*/
    public void paintComponent(Graphics g)
         setPreferredSize(new Dimension(700,500));
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
         Font font = new Font("Serif", Font.BOLD, 28);
         FontMetrics metrics = g2.getFontMetrics(font);
         int hgt = metrics.getHeight();
    // get the advance of my text in this font and render context
    int adv = metrics.stringWidth("C");
         g2.setFont(font);
         g2.drawString("C", 70, 30);
         setBackground(Color.WHITE);
         printFile(g2);
    Edited by: shira on Dec 30, 2007 5:49 AM

    Your jscrollpane is being created anonymously, and there is no way to set the preferred size of this component. I suggest that you create a jscrollpane variable and that you set the preferred size on this variable. I also suggest that when posting code, you use code tags (by pressing the code button after highlighting your block of code), and I suggest that you paste compilable code. Something like so:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    class ScrollPaneDemo extends JPanel
        private JTextArea textArea = new JTextArea(20, 120);
        ScrollPaneDemo()
            setLayout(new BorderLayout());
            setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
            textArea.setWrapStyleWord(true);
            textArea.setLineWrap(true);
            fillWithText(textArea);
            JScrollPane myScrollPane = new JScrollPane(textArea);
            //**** this is the key step here ***
            myScrollPane.setPreferredSize(new Dimension(700, 500));
            add(myScrollPane, BorderLayout.CENTER);
        private void fillWithText(JTextArea textArea2)
            for (int i = 0; i < 10; i++)
                for (int j = 0; j < strings.length; j++)
                    textArea2.append(strings[j] + "\n\n");
                textArea2.append("\n");
        private static void createAndShowUI()
            JFrame frame = new JFrame("ScrollPaneDemo");
            frame.getContentPane().add(new ScrollPaneDemo());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
        private String[] strings =
          "Four score and seven years ago our fathers brought forth on this continent a new nation, " +
          "conceived in Liberty, and dedicated to the proposition that all men are created equal.",
          "Now we are engaged in a great civil war, testing whether that nation, or any nation, " +
          "so conceived and so dedicated, can long endure. We are met on a great battle-field of " +
          "that war. We have come to dedicate a portion of that field, as a final resting place for " +
          "those who here gave their lives that that nation might live. It is altogether fitting and " +
          "proper that we should do this.",
          "But, in a larger sense, we can not dedicate�we can not consecrate�we can not hallow�this " +
          "ground. The brave men, living and dead, who struggled here, have consecrated it, far " +
          "above our poor power to add or detract. The world will little note, nor long remember " +
          "what we say here, but it can never forget what they did here. It is for us the living, " +
          "rather, to be dedicated here to the unfinished work which they who fought here have thus " +
          "far so nobly advanced. It is rather for us to be here dedicated to the great task " +
          "remaining before us � that from these honored dead we take increased devotion to that " +
          "cause for which they gave the last full measure of devotion � that we here highly resolve " +
          "that these dead shall not have died in vain � that this nation, under God, shall have a " +
          "new birth of freedom � and that government of the people, by the people, for the people, " +
          "shall not perish from the earth."
    }Edited by: Encephalopathic on Dec 30, 2007 6:54 AM

  • Easy question about indexes

    Hello,
    I have a table of 100000 rows:
    MyTable
    MyID number(4,0),
    Otherfields ,
    Name varchar2(30),
    LastName varchar(35),
    If I query and just select 60 rows from a total of 100000 rows:
    SELECT MyID, OtherFields, Name,LastName
    FROM MyTable
    WHERE MyID=11
    ORDER BY LastName,Name
    Actually I need an index for MyID field. But would I need an index for LastName and Name? I think I don't, because I'm not using those fields for filtering. Am I correct?
    Thanks!

    With this you could see more in detail the issues to consider at the time to index a table.
    SQL>
    SQL> create table mytable
      2  (
      3  myid number(4,0),
      4  name varchar2(30),
      5  lastname varchar(35));
    Table created.
    SQL>
    SQL> explain plan for
      2  select * from
      3  mytable where
      4  myid=11
      5  order by lastname, name;
    Explained.
    SQL> select * from table ( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |       |       |       |
    |   1 |  SORT ORDER BY       |             |       |       |       |
    |   2 |   TABLE ACCESS FULL  | MYTABLE     |       |       |       |
    Note: rule based optimization, 'PLAN_TABLE' is old version
    10 rows selected.
    SQL> create index i1 on mytable(myid);
    Index created.
    SQL> explain plan for
      2  select * from
      3  mytable where
      4  myid=11
      5  order by lastname, name;
    Explained.
    SQL> select * from table ( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    | Id  | Operation                    |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT             |             |       |       |       |
    |   1 |  SORT ORDER BY               |             |       |       |       |
    |   2 |   TABLE ACCESS BY INDEX ROWID| MYTABLE     |       |       |       |
    |   3 |    INDEX RANGE SCAN          | I1          |       |       |       |
    Note: rule based optimization, 'PLAN_TABLE' is old version
    11 rows selected.
    SQL>
    SQL>
    SQL> create index i2 on  mytable(myid,lastname, name);
    Index created.
    SQL> explain plan for
      2  select * from
      3  mytable where
      4  myid=11
      5  order by lastname, name;
    Explained.
    SQL> select * from table ( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    | Id  | Operation                    |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT             |             |       |       |       |
    |   1 |  SORT ORDER BY               |             |       |       |       |
    |   2 |   TABLE ACCESS BY INDEX ROWID| MYTABLE     |       |       |       |
    |   3 |    INDEX RANGE SCAN          | I1          |       |       |       |
    Note: rule based optimization, 'PLAN_TABLE' is old version
    11 rows selected.
    SQL>
    SQL> drop index i1;
    Index dropped.
    SQL>
    SQL> explain plan for
      2  select * from
      3  mytable where
      4  myid=11
      5  order by lastname, name;
    Explained.
    SQL> select * from table ( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |       |       |       |
    |   1 |  SORT ORDER BY       |             |       |       |       |
    |   2 |   INDEX RANGE SCAN   | I2          |       |       |       |
    Note: rule based optimization, 'PLAN_TABLE' is old version
    10 rows selected.
    SQL>Creating the index i1 you will have pros and cons regarding to the creation of the index i2 and viceversa. If you want to what are them, you could reply
    Joel Pérez
    http://www.oracle.com/technology/experts

  • Easy question about install time

    Hello,
    I have been having a lot of problems with my MacBook and after posting on the forums it seems a re-install might help. This is my firt time doing a wipe/install so I backed up my files and booted from my Tiger install DVD and did a wipe/install and I am staring at in installing right now. It seems to be taking forever! It has been going for about 2 hours now and is about 1/3 of the way finished and says it has 3 hours 43 minutes to go. Is it supposed to take this long?

    Hi,
    I haven't installed Tiger on an Intel Mac but have installed Jaguar, Panther and Tiger a number of times on PPC Macs. It never took more than 30 minutes to complete.
    I would suggest you let the installation run its course and then see how the computer is working.
    It might be that your HD needed repairing... did you check it with disk utility before starting the installation ?
    One more thing... after the first boot (where you set up accounts,etc) you should boot from the install DVD check the disk with disk utility and repair if necessary.
    S

Maybe you are looking for

  • How can i adopt the iPhone App-Structure to iTunes for Sync?

    Hello Community! I usually buy apps or games directly over the iPhone-App-Store and i also manage the folder structure directly on the iPhone Screen. Yesterday i bought a new App via the iTunes Store on my MacBook (don't know why, i thought it would

  • Accessing config information in XML file in a Weblogic web service (JWS)

    Problem: I have implemented a web service for sending emails and pages via Java Mail and SNPP respectively using WebLogic Workshop on the BEA WebLogic 8.1 platform. In the service, I use certain pieces of information that are currently stored in an X

  • Dvd Player: When i insert a movie dvd from the store my .......

    computer begins to play the movie and after about a min or so the movie screen minimizes to the desktop and then either shuts down the computer or puts it to sleep. Most times the computer shuts off once in a while it will just go to sleep. I have tr

  • Iphone 5 Reboot problem please help?!!

    Last night i turned off my iphone 5 and when i woke up i tried to boot it up. It didn't work. I pressed the home button and power button mutiple times and just right when i got the charger and plug it in the usb without the other end in yet it turned

  • PC Suite - How do I keep it connected/Force connec...

    My PC Suite 7.0.7.0 and Nokia N95 (XP SP2) is working just fine. Everything talks to each other, I have another application which talks to the N95 through PC Suite, also no problem... but :-) Sometimes for some reason unknown to me, PC suite looses c