Setting ScrollBars From Child Class

I have a JScrollPane which contains a JPanel that displays an image. I have a rubberband box which will zoom in on the image which works fine. The problem that I am having, is that I need to adjust the JScrollPane's sliders. From within the mouse listener, I zoom the image to the desired scale and after it has zoomed, I call the parent class, JScrollPane to set the sliders to the new ratio. Even though I call it after it has zoomed and I call revalidate, the JScrollPane still has the old values for the sliders and has not updated them. If anyone has any ideas, I would appreciate it.

For ratio.... I just converted the place where I zoomed to as a percentage rather than the exact pixels. So I would zoom in from the jpanel.... repaint the image to the panel, revalidate. I would then call the JScrollPane and set the slider values to, H=35%, V=27%.
I tried your suggestion on overriding getPreferredSize() but I could not get it to work.
I think this will demonstrate my problem a little better:
(from the image panel)
ZoomToBox(image); //scales image to correct zoom and paints to panel(works fine)
this.setPreferredSize(new Dimension(image.width, image.height));
this.revalidate();
jScrollPanel.revalidate();
System.out.println(image.getWidth() + " " + jScrollPanel.getHorizontalScrollBar().getMaximum());
what prints out is (567 1150) which tells me that even though the image has zoomed, the scrollbars have not yet been updated.... then on the next zoom it will display(1150 4602) always beeing one behind. I tried to force setPreferredSize, even tried to force setSize before displaying the values but the scrollpanel is always behind.
For some reason, I dont even know why I tried it, but if I create a new thread to set the scrollbars it works (most) of the time. I dont want to have to do it that way though.

Similar Messages

  • How to set classpath from java class ??

    I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary

    Look into the java.net.URLClassLoader. You can't set the classpath after the fact but you can specify URL's that will checked when you try to load a class with that loader.

  • Set JComponent from other class

    Hi, I have problem from set any JComponent (JButton,JTable, etc.)
    in class from other class.
    I have class A. In class I have JButton and JTable. In this class I have function, in that are I create new instance class B. Class B have function, that are set properties any item in class A.
    class A
    function createAnotherClass(){
    B bclass = new B();
    bclass.setItemInClassA(this);
    function setItem(){
    jTable.setBackground(Color.RED);
    etc.
    class B
    function setItemInClassA(A a){
    a.setItem();
    This is only example, but I need your hepl. Thank you

    hahaha, yeah right,
    i think we do not understand your problem.

  • SwingWorker, setting progress from other classes

    Hi.
    I'm interested in SwingWorker. It's very good tool for long running task in GUI applications. I want to use progress feature, but I don't want to code the logic of my long running task into its doInBackground() method. I have some class (which creates some other classes) which reflects my problem in reality. I want to use this classes for other problems too. So I would like to update progress from this class. Ideal case would be if the method setProgress() in SwingWorker was public, so I can create optional constructor with additional parameter for SwingWorker class (and its subclasses) and call method setProgress from this class. Does anybody know about some solution? I'm still thinking over, but I cannot find ideal solution.
    Thx for help

    Your configuration remains incomprehensible.
    From the other thread you mention a Listener which gets asynchronous messages. Are we talking about a context listener which handles JMS messages or the like? From these message you get a value and set it in a bean property.
    Then we get lost. You say you want to pass this value to a Servlet, presumably by passing a reference to the bean. But how is a particular incoming message associated with a transaction going through the Servlet? How do you imagine the bean reference being passed. A ContextListener doesn't see the web transactions. Should these bean values affect all subsequent transactions? Is there some kind of key in the web transaction that makes it look for data from a particular JMS message?
    In general the way for a ContextListener to pass data to a Servlet is by setting attributes in the ServletContext, but you really haven't made clear what you're trying to achieve.
    Try explaining in a more general way what your project is trying to achieve. You're concentrating on details which almost certainly don't contain the problem.

  • Setting variables from inner class

    I have a GUI that takes users information and provides a quotation as componants are clicked. My componants' Listeners are in seperate inner classes and from these I want to add certain details to variables, it seems to compile and run but it doesn't seem to be changing the value of the variable when the componants are clicked, is there any reason why this happens, my code is below:
    public class MyGUI extends JFrame{
            public MyGUI(){
              //GUI STUFF HERE
            double Price;
         private String total=calculate();
         public String calculate(){
              double aTotal=Price;
              return "$ " + aTotal;
         class MyListener implements ItemListener{
              public void itemStateChanged(ItemEvent evt){
                   if(evt.getSource()==rad1) {
                   Price=0.10;
                   else if(evt.getSource()==rad2) {
                   Price=0.12;
                        totalLab.setText(total);
    }

    shouldn't I also be able to access the outer classes methods? It doesn't seem to do this either.

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

  • Setting final Instance variables in Child Classes

    Hello:
    Is it possible to declare (not initialize) a final variable in an abstract parent class and set it in a non-abstract child class.
    An example for clarification.
    I have an abstract parent class (call it P) and two child classes (call them (C1 and C2). There is common processing that goes on in P. This processing uses a variable called x. C1 will set x to equal 10 and C2 will set x to equal 20. Can I declare x final in the abstract class P and set it in C1 and C2
    This is impossible right? I know some other languages allow this behavior so I just wanted to make sure that Java does not support it.
    Thanks
    Johnny

    Why don't you just try it out? Though I'm pretty sure it won't work, as it should expect all constructors of the abstract class to set it. But you could either let there be an overridden method that returns the appropriate value for the sub-class:
    abstract class P
      abstract protected int getTheValue();
    class C1 extends P
      protected int getTheValue() { return 10; }
    class C2 extends P
      protected int getTheValue() { return 20; }
    }

  • Executing a child class from parent.

    Hi, well, I have this parent class which I need to execute a method from a child class to get a significant part of the thing get started. Is there anyway for me to accomplish this or a workabout? Thanks..

    Sure.. I have this method in the class logic:
         public void createLocation() {
              try {
              classCoord coordSet = appinterface.decodeFile();
              int areaNum = coordSet.areaNum, cellNum = coordSet.cellNum, signalStrength = coordSet.signalStrength, receiverId = coordSet.receiverId;
              String dateTime = coordSet.dateTime, userName = coordSet.userName, location = calLocation(areaNum, cellNum);
              boolean validity=calValidity(signalStrength);
              classLocation locationObj = new classLocation(this.type, userName, receiverId, validity, location, dateTime);
              appinterface storeLocationObj = new appinterface();
              storeLocationObj.storeLocation(locationObj);
              catch (IOException ioException) {
                   appinterface.displayMessage("Logic Error: " + ioException);
              catch (ClassNotFoundException classNotFoundException) {
                   appinterface.displayMessage("Logic Error: " + classNotFoundException);
         }I need to execute this method halfway in the class appinterface, the logic class inherits from appinterface cuz I need to make use several methods from it. Is there any way to solve this somehow?

  • How to listen to user actions in child class from parent class?

    Hi,
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:
    textField.addKeyListener( new KeyAdapter()
                @Override
                public void keyPressed( final KeyEvent e )
                    //user typed something
                    userTyped = true;
             });Now I have another parent class that uses ChildCustomForm, and parent class has to know once user types, then set
    its own userTyped flag.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).
    I am wondering if there is a way to do this?
    regards,

    jack_wns wrote:
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:You want to listen for input into the textbox, correct? This may take the form of keyboard input, or could be a paste-text event in which case your keylistener will miss it. I recommend that you look into a DocumentListener here so you will catch any changes, be they keyboard or cut or paste.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).The observer pattern may work here.

  • Calling father from the child class?

    Hi...
    And I want to learn how to:
    public class FATHER{
    int SAMPLE=0;
    FATHER(){
    Child mychild=new Child();
    class Child{
    Child(){ 
    // I am child and I want to set my father's(who created me) SAMPLE var...
    here is a small example.. I could not reached fathers variables in the child.. there must be an easy way to do that ..
    Thanks ...

    Actually, why would that happen?Because the father tries to create a child, itwill
    become recursive.
    KajOh, so it will become recursive due to the
    constructor in the Father class?Nope, because of the ctor of the child class because it'll call either
    implicitly or explicitly the father's ctor again.
    kind regards,
    Jos
    ps. see for yourself:class Father {
       private class Child child;
       public Father() {
          System.out.println("father ctor");
          child= new Child();
    public class Child extends Father {
       public Child() {
          System.out.println("child ctor");
    }

  • Class override, how to create the child class and then the base class

    I started to write a program for a smart DMM, the problem is every version of the DMM the company change the communication commend.
    My idea is to write a child class for every DMM version and every SubVI of the child will override the base class SubVI.
    My problem is, i want first to create one child class and after i will see every thing is work,  start to create the base class. that way i will see if am thinking the right way.
    My question is
    How can i create a child class and then create the base class and configure the SubVi of the child class to be Override of the base class?
    I tried to search in the property of the class but i didn't see nothing.
    Thanks
    Solved!
    Go to Solution.

    This can be done and I've done it on occasion.
    You simply create the base class with the dynamic dispatch methods you require (connector panes need to be identical to thos of the child class).
    Then set the inheritance of the class to inherit from this base class.  If your method is defined as a dynamic dispatch method in the parent, you'll most likely now have some errors (unless your child method was already DD in which case you might just be OK already).
    To change the inheritance of a class, right-click the properties of the class in your project and select properties.  I believe the ineritance tree is at the lower end of the properties.  Click on the "change inheritance" (or something similar) to choose the class from which you now wish to inherit.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Copy multiple dispatch vi to new child class

    Hi, I have just started with LVOOP and while I'm pretty sure I have a good understanding of the overall theme, there is one problem I foresee if I continue.
    Situation:
    BoardType is parent of classes CC2600 and CC1300. Currently the child classes are just empty place holders.
    Almost all the methods in the child classes will be of dynamic dispatch type (currently only one).
    From what I understand a dynamic dispatch must be available in all child classes plus parent class in order to work as intended. 
    Problem:
    If I would go forward and implementing LVOOP this would require approx 30 dynamic dispatch vis for each class. I can right click but for just these two children that's 60 + 30 vis I must create manually. I would much prefer just to create a template once and then just basically drag and drop 30+ new vis for each new class that is created.
    Is there a way I can define a set of template dispatch vis in the parent BoardType and have them added to all the child classes? 
    I tried the save as copy, but the problem is that I still have to replace the connector pane to represent the new owning class.
    If it helps here's a very basic block diagram of what's going to happen, just after Reset.vi there will be a lot of other dynamic dispatch vis.
    Thanks in advance.
    Michael

    From the OP it sounded like you were literally just copying from the parent.
    What I tend to do is finish one child class and then save a copy to a new name and change the internal data (if required) and DD vis (if required).
    I do agree though that these kinds of operations could be hugely simplified using helper programs.  Give the link provided by others a try.
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Passing parameter value back from Child region [BTF] to Parent

    Hello,
    I am using Jdev 11.1.1.6. I have a use-case where I need to pass value back from child taskflow to parent.
    Let me elaborate the use-case:
    I have a main page which is implemented as BTF with fragment. This main page contains a child region [again a BTF with fragment].
    I am passing a parameter value from parent page to it's region using taskflow input parameter. Now value for one of the parameter changes inside child/region taskflow and I need to make this value available to main page taskflow.
    This parameter is just pageFlowScope variable, so basically not coming from any VO.
    I know that taskflow can return value via return parameter but I don't know if that is true for taskflow implemented as region in a page.
    Is it possible to communicate the pageFlowScope variable value from child region to it's parent page?
    Thanks,
    Jai

    Hi Frank,
    I tried to follow steps mentioned in your post but encountered error that "The scope of the referenced object #{viewScope.parentBeanName} is shorter than referring object childBeanName"
    Let me explain what I did:
    1. Created a bean parentBeanName in viewScope
    2. Created another bean childBeanName in pageFlowScope
    3. In ChildBean.java, created a private property parentBeanProperty for Class [ParentBean] and generated the accessors
    4. Created a input parameter in region TF as:
    <input-parameter-definition id="__28">
          <name id="__27">parentBeanParam</name>
          <value>#{pageFlowScope.childBeanName.parentBeanProperty}</value>
          <class>ParentBean</class>
          <required/>
    </input-parameter-definition> 5. Since my mainPage contains child page as region. I added parameter to mainPageDef to pass it to child TF, like this
    <parameter id="parentBeanParam" xmlns="http://xmlns.oracle.com/adfm/uimodel"
                       value="#{viewScope.parentBeanName}"/>6. Introduced a client method in childBeanName that is called from UI. There I am retrieving parentBeanParam instance from pageFlowScope and call setter method of my variable inside ParentBean.java
    7. Ran the page but encountered the error.
    Did I miss something somewhere?
    Initially I got error where #{viewScope.parentBeanName} returned NULL due to parentBeanName not instantiated. I created a variable in mainPageDef with it's default value pointing to #{viewScope.parentBeanName.variableName}, which I guess will instantiate the bean in viewScope.
    After this I got error of shorter scope. It never reached to code in Step 6 during execution cycle.
    FYI - My application is based on UIShell and essentially a one page application. Main page referred above is also a jsff based on BTF. I hope, this should not affect this implementation but I thought of at least mention it.
    Thanks,
    Jai
    Edited by: Jai Om on Dec 18, 2012 2:38 PM

  • Child class not called at run time labview

    I'm developing a large application using a few Class.
    In development mode, everything works fine.  When I build the application and run the executable, one of my child class is not called at all.  In some of the methods of that child class I have checked the option in "Window Appearance" to show the Front Panel when VI Load.  The VI show it self but is not executing.  The run button is in a state that indicate there is no top vi calling it.
    I have played whit Execution : Preallocated clone reentrant execution and General: Separate compiled code from source file.
    And I set them back to default.
    Two days lost trying to figure what append to my application.
    Please Help.
    Nitrof

    Hi Nitrof,
    Check out this excerpt straight from the NI Training Manual on object-oriented programming (image attached). There's a chance that the child classes aren't being included in the build. They need to be included somewhere in the application VI so that the Application Builder knows to include the class in the build.
    Also check out this forum that sounds like it's describing a similar problem: http://forums.ni.com/t5/LabVIEW/Problems-with-dyna​mic-class-load-in-executable/m-p/2139116
    Hope this helps!
    Alexandra
    National Instruments
    Applications Engineer
    Attachments:
    Forum1937225.png ‏146 KB

  • Can I make methods which are public in a parent class into private in a child class ?

    I suspect the answer to my question is probably no, but...
    I have a parent class that provides several general purpose methods, I also have a child class which is intended to provide a more specific set of methods for manipulating the data in the class. As a result, calling some of the parent's methods on the child class can provide results that I'd rather not let the users of the child class have to worry about. It seemed (from my rather naive OOP experience) that the nicest way to do this would be to make access to some of the parent's public methods be private in the child class. This doesn't seem to be trivially possible.... ?
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/

    Hi Gavin,
    Unfortuneately I don't think this can be done. You can use an overide VI to change the functionality of a method in a child class but it has to have the same scope and the method it overides.
    Regards
    Jon B
    Applications Engineer
    NI UK & Ireland

Maybe you are looking for

  • Cost Center Infoobject in Custom development

    Hi all I need to use the infoobject 0costcenter in one of my custom ODS/CUbe developments . However , when i add the infoobject 0costcenter to my infosource , the compounded object' 'chart of accounts' also gets added . I am not sure if i this will s

  • Adding Bubble text effect

    Hi there Does anyone know if and how you can add bubble text effects to still images on FCE? Or is there a program out there that you can do it in and then import into FCE? Thanks

  • Visio 2013 Default Line and Connector Styles

    This question has been asked previously, but the answer is not sufficient. In the older versions of Visio, all you had to do was right-click and select the "set as default" option to set the default style for lines/connectors/shapes. Where is this op

  • Console reports 10sec process that repeats and repeats!

    This started happening after I updated to iTunes 7.5 and Quicktime yesterday afternoon and I cannot figure it out! I didn't remove anything that would have caused this! Can anyone figure it out? Also as a result of this, my keyboard is getting screwy

  • logic:equal + hashmap

    hi i have a bean in jsp which has a HashMap like this <bean:define name="actionFormSample" id="sampleBean" property="myHashMap" type="java.util.HashMap"/>. Now i have to use <logic:equal>tags to compare value of a key in the hashmap only if it is YES