Calculate the rectangle size displayed in JScrollPane

Hi,
I am pasting a code below, What i want to get is the the rectangle of panel which will be displayed, so i can use g.setClip method to only paint that much portion of the JPanel
Please copy the code compile it and run it, so u will come to know my problem..
I want to dynamically setClip so the display is proper when the user scrolls.
Ashish
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestDisplaySize extends JFrame
     JScrollPane scrollPane ;
     public TestDisplaySize()
          super("layered pane");
          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          MyPanel panel = new MyPanel();
          scrollPane = new JScrollPane(panel);
          Container contentPane = this.getContentPane();
          contentPane.add(scrollPane, BorderLayout.CENTER);
          setSize(new Dimension(800,600));
          this.setVisible(true);
     class MyPanel extends JPanel
          public MyPanel()
     setPreferredSize(new Dimension(2000,600) );     
     this.setBackground(Color.white);
     this.setOpaque(true);
     public void paintComponent(Graphics g)
super.paintComponent(g);
g.setClip(0,0, 750,550);
g.setColor(Color.blue);
int x = 0;
for(int i = 0; i < 60; i++)
     x +=60;
     g.drawLine(x, 0, x, 600);
     public static void main(String args[])
     new TestDisplaySize();
}

ash,
Use this:
super.paintComponent(g);
Rectangle r = scrollPane.getViewport().getViewRect();
g.setClip((int)r.getX(), (int)r.getY(), (int)r.getWidth(), (int)r.getHeight());
g.setColor(Color.blue);--A
PS: in future please see the "special tokens" link in the posting page for special tags that will make posted code format better.

Similar Messages

  • How do I calculate the total size of selected folders?

    Hello
    My question is:
    How do I calculate the total size of selected folders?
    Thank you

    It does show the aggregate size.
    Command-Option-I opens the Inspector window. (Or open the File menu and hold the Option key. Get Info turns into Show Inspector.) The Inspector is similar to the Get Info window but it shows aggregate info for multiple selections. It is also dynamic — if you change the selection while the Inspector is open, the info changes to reflect the current selection.

  • Calculate the database size for a particular company code in SAP

    Hi Experts,
    We have 30 company codes in our FI production system. So to plan another new company code to be deployed into the system, we need to know exact data capacity (database) of the previous company code that we already deployed. Kindly let me know whether it possible to calculate the database size occupied for a particular company code in a SAP system.

    >
    Kalyan Kumar Bandlamudi wrote:
    > Hi Experts,
    >
    > We have 30 company codes in our FI production system. So to plan another new company code to be deployed into the system, we need to know exact data capacity (database) of the previous company code that we already deployed. Kindly let me know whether it possible to calculate the database size occupied for a particular company code in a SAP system.
    Its not possible to calculate data size based on company code.
    By creating company code It will not occupy much space. Depends on your posting documents for particular company codes.
    Thanks
    Siva

  • HT1338 Why isn't the file size displayed for software updates in the App Store?

    Why isn't the file size displayed for software updates in the App Store?
    My only internet connection is a tether to my iPhone.
    My limited bandwidth forces me to manage my data consumption - I am forced to "google" the file size of the software update so I can decide if I have the headroom in my data plan to take advantage of the update.

    If you click on the name of the Application in your Updates Available list,
    it will take you to the update Imformation for that App.

  • How to calculate the row size

    Hi,
    I am having a table of 4 column. First column is varchar2(10), Second column is Number(5), Third column is char(10) and Fourth column is Number(12,2).
    Now how to calculate the size of each row. I want to know how much space it will take for each row.
    Thanx & Regards,
    Swarup

    For a complete discussion of storage requirements for different datatypes see the Oracle 8i Concepts manual.
    All Oracle documentation is available on-line via the 'Documentation' link on the OTN home page.
    Your Col2 NUMBER(5) will take 4 bytes if it holds a 5 digit positive or negative number.
    Your Col4 NUMBER(12,2) will take 7 bytes if it holds a number with 12 digits that is positive and will take 8 bytes if it holds a number with 12 digits that is negative.
    The following is from the Concepts manual Chapter 12 (Copyright by Oracle)
    Built-In Datatypes 12-9
    Internal Numeric Format
    Oracle stores numeric data in variable-length format. Each value is stored in
    scientific notation, with one byte used to store the exponent and up to 20 bytes to
    store the mantissa. The resulting value is limited to 38 digits of precision. Oracle
    does not store leading and trailing zeros. For example, the number 412 is stored in a
    format similar to 4.12 x 10 2 , with one byte used to store the exponent (2) and two
    bytes used to store the three significant digits of the mantissa (4, 1, 2). Negative
    numbers include the sign in their length.
    Taking this into account, the column size in bytes for a particular numeric data
    value NUMBER ( p), where p is the precision of a given value, can be calculated
    using the following formula:
    ROUND((length( p)+ s)/2))+1
    where s equals zero if the number is positive and s equals 1 if the number is
    negative.
    Zero and positive and negative infinity (only generated on import from Version 5
    Oracle databases) are stored using unique representations. Zero and negative
    infinity each require one byte; positive infinity requires two bytes.
    null

  • A Custom tag/servlet that calculates the session size ?

    Hi all,
              is anybody aware of a custom tag/library that calculates the size of the Session ?
              Thanks a lot
              Francesco

    250 lines, lol.  You need a loop then.
    // Function in document JavaScript
    function calcTotal() {
    for (var i = 0; i<=249; i++){
        this.getField("Total1.0." + i).value = this.getField("Price1.0." + i).value * this.getField("Qty.1.0." + i).value;
    Launch this script only ONCE in a custom calculate script and the script will run through all 250 lines from line 0 to line 249.
    to launch it:
    //put this in a calulate script
    calcTotal();

  • I cant' control the font - size displayed during edition is different from the ones (1 or more - never know) sent.

    1) When I edit my e-mail, the font is always the same - arial 10 pts. But once the e-mail is sent, what I can see in my 'sent' box and what the receiver gets is all messed up, especially when I have pasted some text. There are parts with huge font and there are with such a small one that it's difficult to read it. Or the whole text is extremely large or tiny.
    I need to write in HTML for I often must highlight some parts. I searched many forums but nowhere found any answer.
    2) When i get an e-mail the problem is similar: it can be written with the letters you can distinguish from the other side of the room or on a contrary - you would use binoculars to read it comfortably. The least font is set to 10 pts.
    Thunderbird 31.3.0, Win 7 (64).

    From John Waller: “If you're using IE8, hit F12 to launch Developer Tools which give you a point and click method of locating the relevant CSS rule on screen.”
    I have Internet Explorer 8 (IE8) so tried this method.
    This sounded like another promising possibility; however, I have not been able to change the font size in my post using this method.
    I have gone to Dashboard > Posts > Edit > then moused-over my post > clicked on "edit" and then hit F12. An enormous amount (20 pages or more) of CSS appears. I tried picking out the font size that I thought pertains to the post (under Text Area), and I have changed the font size from 13px to 24px; however, I have not been able to “save” the new setting. When I go back to it, it is back to 13px.
    As a result, I have not been able to use a trial-and-error method to establish which font size I must change in order to change the font size of my post.

  • How can I calculate the total size of my email messages?

    I have an iMac and MacBook Pro. I use Apple's Mail application on each computer and have three email accounts that are feeding into it. I currently synchronize everything through MobileMe. I want to know how to calculate how many MB (probably several GB!) of space my email messages are now using, as I want to upgrade to Lion on the two computers and will soon be getting a 32BG iPad on which I would like to use the Mail application as well. I'd like to know in advance if I need to pay for more than the 5GB of free storage that iCloud will give me before making these changes, as I don't want to lose my email messages. For various reasons, I'd prefer not to go the route of archiving the messages. I can't figure out how to calculate how much space the messages are currently using.

    The important detail is the cylinders not the partition numbers. The partitions are simply slots where cylinder space can be assigned if its available.
    The backup partition (2) represents the whole disk and shows you have 14086 cylinders available.
    But you'll notice that all of those cylinders are already assigned to various partitions. So there is no free space available.

  • How to calculate the partition size in range partition,by value

    hi all,
    The primary key is number for the table.
    I have 5543201 records in a table.
    If I want to break them in 7 equal partition as per the primary key,how do i achieve this?
    rgds
    s

    I probably don't understand it...but I would say:
    5543201/7=791886
    range 1 : 0....791886 (1x 791886)
    range 2 : 791887....1583772 (2 x 791886)
    range 3 : 1583773 .... (3 x 781886)
    tange 4 : ......
    HoweverI doubt whether this is a smart aproach for partitioning.
    I would say that a patitioning on date, or some key-value is more applicable.
    But hey...I don't know the further requirements.
    Cheers Martijn

  • How to calculate the real height of the text in RichEditableText control?

    Hello,
    I created a new component by extending the RichEditableText control.
    When I try to get the value of contentHeight propery of this class even after compositionComplete event has fired, I get incorrect content height (so called "estimated" height). I was able to obtain the correct value only ater I set verticalScrollPosition to a value beyond this estimated content height thus causing the class to calculate real text height. Here is a code snippet.
    public class ViewerController extends RichEditableText
    public function loadText(){
       var tf:TextFlow = TextConverter.importToFlow(LONG_XML_FILE_WITHOUT_PICTURES_GOES_HERE as XML, TextConverter.TEXT_LAYOUT_FORMAT);
       //Events  
       tf.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionComplete);
       tf.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE, pictureLoaded);
       this.textFlow = tf;  
       this.verticalScrollPosition = 0;  
       this.textFlow.flowComposer.composeToPosition(); // I assume this makes the control calculate the real size of the text
    private function pictureLoaded(event:StatusChangeEvent):void {
    private function compositionComplete(event:CompositionCompleteEvent):void {     
    But what if I want to know the real height BEFORE I scroll to the very bottom of the text (or before even displaying this component)?

    SDN is not your code factory, please research yourself before posting, maybe ask whoever handed you this requirement?
    Thread locked.
    Thomas

  • When using Google to search the results are displayed so small I cannot read them. This just started today.

    Today when I was searching with Google. The display of the results started getting smaller and smaller, right before my eyes, and I could not stop it, and I was doing nothing, but reading the screen. I cannot find anything to tell me how to get the larger size display back. All the other search engines, such as Bing, Yahoo are displaying correctly. I have always used Google, I like Google, I do not want to change. Please can you help me? I have a screen print available is you need to see it. I tried searching the Google website for help but I couldn't find anything. I installed something called Stylish, thinking that would help, but it did not.

    hello, try to press ctrl+0 ('zero') while you're on the page in order to reset the zoom level or in case this doesn't work also go through the other common troubleshooting steps at [[Websites look wrong or appear differently than they should]].

  • How can I calculate the number of members with data for a given Dimension

    HiI want to be able to calculate the exact size of the data given the number of blocks in existence.I am trying to work out a way of estimating the effect of changing Dimensions from Spare to Dense and to see which Dimensions would be worth it.Currently I have Cost Centre and Reference Code dimensions. I know that roughly 90% of the Cost Centres are used against just one member of Reference Codes but the other 10% are against multiple Reference Codes.I also have a number of other dimensions and the problem I come up against is that when I change a Dimension from Sparse I really don't know how many blocks will be in existence at the end of it so I can't multiply this against the blocksize to predict the total datasize.Any thoughts (the artistic "suck it and see" solution is obvious but I'd like to cut down on experiments - they take too long)Thanks

    You can do it manually if you like with code in the Error Console.
    Copy and paste the code in the Code field in the Error Console and click the Evaluate button.
    *Firefox/Tools > Web Development > Error Console (Shift+CtrL+J)
    See http://kb.mozillazine.org/User:Dickvl/JavaScript_Error_Console#Expire_History_By_Days

  • Setting the heap size

    Hi all,
    I wanted to ask you about setting the heap size value.
    How we can calculate the heap size?
    I had problems with the max heap size in my application.
    So I increased the max value to 2048 MB, but I am afraid that
    the same error may come up again some time depending upon the
    usage.
    So how I can find, say for a server having 2 GB RAM,
    how much heap size I should give? I read that there is no defined
    formula to calculate this. But I wanted to get the best way of doing it.
    Please advise,
    Sandeep

    As has already been said, you probably have a leak. However, when trying to gauge the maximum heap you can (not should, but can) use you have to take into account what the server is doing, and its operating system. You do not want your JVM to page. So, for a 2GB server, with no other app on it, I think the "usual" is something like 75% max? Though I really wouldn't take my word for it...it's not my field.

  • Rectangle size grows while uploading in server

    hi all,
    i put two table inside a ractangle. the two table has some data. while uploading the same in the server the rectangle size grows automatically but while checking in local it doesn't shows any problem. i am using ssrs 2008r2 for creating report. any
    help for  problem will be appriciated.
    regards
    swati_1

    Hi swati_1,
    In SSRS, when we add tablix in a rectangle, the rectangle would automatically adjusts to the height of the tablix. However, the space white of the rectangle is invariant. We can adjust the rectangle size to fit the tablix to shrink the space area.
    Reference:
    http://social.technet.microsoft.com/Forums/en-US/a2924034-fa2f-46df-8cea-e418cdb7a4f4/rectangle-auto-growing?forum=sqlreportingservices
    Alternatively, you can try to place a text box at the bottom of it to resolve the issue. If the issue is persist, I recommend you vote the following feedback.
     https://connect.microsoft.com/SQLServer/feedback/details/383350/add-can-grow-and-can-shrink-properties-to-rectangle-control
    Your feedback is valuable for us to improve our products and increase the level of service provided.
    If there are any misunderstanding, please elaborate the issue for further investigation.
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • Can the font size in Itunes Help files be increased? The font size is way to small to... 4pt!

    Itumes for Windows 10.6
    Windows 7 x 64
    Is there a way to increase the font size displayed in the Itunes Help files? The size seems to be < 4pt and very difficult to read. Please advise.

    Sometimes this can be altered by going inside the "plist" for the project and making specific changes. It is beyond my scope, but someone on these forums should be talented enough to suss it out.

Maybe you are looking for

  • A sort of KeyListener without a GUI Component?

    a sort of KeyListener without a GUI Component? ( or any trick that will do)? please be patient with my question I can't express myself very well but it's very important. Please help me I need an example how to implement a way to detect some combinati

  • HP LaserJet Pro CM1415fnw - lastest firmware Version:20120629 - wireless lost after around 10mins

    I hope someone can help / explain this.. I updated my firmware to the latest version 20120629 last night.. since then I noticed I lose wireless connection around 10mins. I check the wireless = OFF and unable to turn back on. The only way to recover i

  • Getting data from multiple hard drives onto one drive

    So here's the problem: I have a Quicksilver 867 I want to upgrade, it came with no HD so I want a new one, I put my old strawberry imac's HD into it because I still have a use for all the programs on it (i.e. photoshop) and I wanted to take advantage

  • Synchronous AS2 - MDN communication

    Hello, in our AS2 scenario (SAP Proxy Sender --> BPM --> AS2 Receiver) we request the MDN synchronously for error handling purposes, associating the message directly to the sender message and direct update of the sender system. However problem is tha

  • Picture Messages not displaying in threads

    I have started to experience a new issue with my iPhone 5 this week. There have been several instances where I have sent a picture message to someone, after I send the photo, i go back to the messaging thread a few moments later and it doesn't show t