Zooming causes components on JPanel to displace

Hi friends,
my english is somewhat weak, but i am trying to clear my point.
I have a prob regarding zoom. In my application I have A JPanel which is drawing some rectangles on it and having some JLabels. My prob is when i zoomin my JPanel through my zooming code and try to select any of JLabel ,I am not actually selecting labels by just clicking on the label but i have to make some random guess on JPanel to select that label.
I am not getting what mistake i m making there. may be i would have to move my labels by some distance on zooming(but its only my view). if any of you have some ideas then please do tell me.
thankyou

I second camickr's recommendation for you to study the tutorials. A few specifics:
public void paint(Graphics g){
   g.setColor(Color.black );
   drawDisplay(g);
}* Don't override the paint method of a JPanel, override the paintComponent method.
* You will need to call super.paintComponent(g) within your paintComponent override. This may need to be the first line in fact.
* As noted by camickr, do not place AWT components on a Swing component (JPanel).

Similar Messages

  • How to use scale method in Graphics2D for zoom in/out in JPanel.

    Hi All,
    Iam working on zoom functionality, I have JPanel as my Drawing view while creating iam setting scale as 1.0D... if you click on zoom in or zoom out button iam again setting the scale of graphics2D object like below.
    if(!(g instanceof Graphics2D)) {
    super.paint(g);
    return;
    else {
         Graphics2D g2 = (Graphics2D)g;
         g2.scale(m_dMagnitude, m_dMagnitude);
         super.paint(g2);
    As i added my JPanel on JTabbedPane and when i try to zoom out the view you can see the color difference as both have different back ground color. And when iam trying to add any graphics object it's not adding where you click mouse.
    Can any buddy let me know is there any way to do this, if any one have code pls pass to me.

    The only way to access a protected variable is to subclass.
    MyCalendar extends Calendar
    but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
    cal.isSet( Calendar.HOUR );

  • Testing iMac in store I checked iPhoto editing. Photo said to be 42Mb but zooming caused immediate pixellation, so clearly was not displaying a 42Mb file. When I zoom in PS on PC a large file retains detail for a lot of zooming. Whats going on?

    While testing a MacBook pro in the Apple Store, I checked iPhoto. Looking at what was said to be  42Mb file I noticed that zooming caused immediate pixellation, so clearly a 42Mb RAW file was not what I was looking at. In my PS Elements on my PC when I zoom, the photo remains unpixellated until quite a lot of zoom is used (marked as 100%). This depends on the file size of the photo of course. Maybe the displayed photo in iPhoto is a low res. jpeg. This is not too good for me. I wanted to see how the base model of MacBook would handle photos esp large files and I need to zoom in. Will the base model cope with this in PSE for Mac?

    iPhoto will happily zoom to 300%. The quality at that magnification will depend on the quality of the image.  But if it's a sharp image - of any size - it will zoom to 300% with no problems.
    PSE for Mac has nothing to do with iPhoto. I have used it with no problems, but for best information why not ask over at the Adobe forums?

  • Can't show J components on JPanel

    Because I'm a begineer, I'm not sure I can explain my problem correctly.
    The problem is quite simple.
    I'd like to show some J components on JPanel but I can't.
    I made a JFrame which has 5 JPanels.
    Each JPanel has some components and calls paint method to draw some lines.
    public void paint(Graphics g){
         g.setColor(Color.black );
         drawDisplay(g);
    When I put AWT componts such as Label, Button etc, there's no problem.
    But when I put J components like JLabel, JButton,
    I cannot see the components. Sometimes I can click JCombo box....
    Interestingly, when I remove the paint method, J components show up on interface.
    Anybody understand this situation?
    Do I have to know something for this?
    Thank-you.

    I second camickr's recommendation for you to study the tutorials. A few specifics:
    public void paint(Graphics g){
       g.setColor(Color.black );
       drawDisplay(g);
    }* Don't override the paint method of a JPanel, override the paintComponent method.
    * You will need to call super.paintComponent(g) within your paintComponent override. This may need to be the first line in fact.
    * As noted by camickr, do not place AWT components on a Swing component (JPanel).

  • How can we add components to JPanel so that they can be resizeable

    Is it possible to add components to JPanel so that we can resize them or drag them.

    You could try searching the forums, but I'll save you the trouble. tjacobs has oft posted code which does what you want, both dragging and resizing.
    You can find an example here or here.

  • For Safari, on web pages, including this one, the use of ' (apostrophe) causes erratic behavior in text boxes. A contraction such as "I'v |e " has caused the cursor to backspace, displacing the e when the space bar is hit, or causes a juAsk your question.

    For Safari, on web pages, the use of ‘ (apostrophe) causes erratic behavior in text boxes. A contraction such as “I’v |e “ has caused the cursor to backspace, displacing the e when the space bar is hit, or causes a jump out of the text box and a return to the top a a page when used for the first time right at the beginning of text.
    Other browsers do not have this problem. When will Apple fix this problem?

    From the menu bar, select
    Edit ▹ Substitutions
    and uncheck Text Replacement.

  • Sticking components in JPanel to GridLayout

    Could please anyone help in the following.
    I have an application where some JPanel with several Swing components
    positioned with help of GridLayout. What I need is to
    remove and place components during runtime,
    but the problem is that when I remove component placed somewhere
    inbetween with use of the method remove() of the class JPanel,
    all components are shifted so that the empty space is filled and
    even one can see that the initial GridLayout is destroyed.
    How can I stick all components to the initial grid cells of GridLayout?
    I mean I do not want components to shift anywhere from their original
    cells.
    Thank you in advance.

    Well, that solution is what I came to also.
    I mean I replacing removed compenent with some other invisible component.
    But is this indeed the only way?
    I tryied the method removeLayoutComponent() in the class GridLayout, but
    I have not understood how it works and what it is for.
    When I tryied it instead of remove() (of JPanel) it did not remove anything,
    but it looks like something relevant to my situation.
    PS The second line of my orginal poster should be read
    "I have an application where some JPanel is created with several Swing components
    positioned with help of GridLayout in it".
    Sorry...

  • How to Zoom In/Out on JPanel

    Hi,
    I am working on an application and it that i have created one JPanel and added custom components to it.
    Now my problem is i want scale the JPanel, how an i do that and after scaling the Jpanel i want the all components i added in that also scale and reposined accordingly. Also i want to handle the event from that components after scaleing.
    Thanks in advance.

    all components i added in that also scale and reposined accordingly.Sounds like you want a Layout Manager, possibly GridBagLayout.
    i want to handle the event from that components after scaleing.If I understand that correctly, you want ComponentListener.componentResized and/or componentMoved.
    db

  • Browser zoom causes typing lag

    When using Outlook.com mail, my user noticed a typing lag. I reset IE, disabled all startup items, tried an external keyboard on this laptop, deleted the built in keyboard driver and let it redetect on reboot, tried Google Chrome as an alternate browser.
    No typing lag in any other app such as WordPad. I found that in IE or Chrome, 125% zoom was fine but as soon as I set it to 150%, the lag came back, that was the common denominator.

    Hi,
    This issue can be caused by video card and GPU acceleration.
    Please disable GPU acceleration in IE and Chrome, and if you have Graphic card software, please also disable the GPU acceleration on it to check the results.
    How to enable or disable software rendering in Internet Explorer 9
    http://support.microsoft.com/kb/2528233
    Note: If your IE is not version 9, only try the manual steps in about article.
    Windows 7: Chrome GPU Hardware Acceleration - Turn On or Off
    http://www.sevenforums.com/tutorials/271264-chrome-gpu-hardware-acceleration-turn-off.html
    Also, update the driver for the graphic/video card driver to see what's going on.
    Kate Li
    TechNet Community Support

  • Updating components in jpanel

    Hi, all
    I have a report application which will update me system utilization in several jpanel. Those panels stored in a hashtable and I programmed it refresh each 5 minutes. Here is how I do it.
    Step 1: remove all
    mypanel=(JPanel)panels.get("1");
    mypanel.removeAll();
    mypanel.validate();
    Step 2: show progress
    mypanel.add(<updating message in jlabel>);
    mypanel.add(<a progressbar>);
    mypanel.validate();
    Step 3: add new content
    mypanel.removeAll();
    mypanel.add(<a graph in jlabel>);
    mypanel.add(<a jtable with data>);
    The problem is the old content still remains when progress bar appeared. Didn't I just remove all components in step 1? How can I have a empty panel with only progress bar?
    Thanks,
    Vincent Chen

    Damn, I found what the problem is, but if I gave the solution to the OP, that would mean confessing I have followed the link, and admitting to belong to the "not worth mentioning" category!Well, since my cover's blown anyway, let's caugh it up:
    Your have an attrubute searchType of type SearchType, you initialize it to reference a new SeearchType() , and you use its status for the search, however you never add the instance in the panel's widget hierarchy. Instead you add a new SearchType() .
    Same for attribute style :
    searchType = new SearchType();
    style = new Style();
    this.add(new SearchType(), c);
    this.add(new Style(), c);
    // in event handler
    search(txfQuery.getText(),searchType.getSelected(),style.caseSensitive(),limitation.getLimNum());
                                    ^
                                    *At this point, the instance referenced by searchType has never been displayed, so the checkbox, combobox, and whatnot that the user has interacted with are not the ones whose state you read.

  • Handling focus on components within JPanel

    I have a custom component called a DmsField which extends JPanel. "Dms" means degrees/minutes/seconds. It's a JPanel with a two-button JRadioButton group for the sign, and three JFormattedTextFields for degrees (int), minutes (int), and seconds (float, 2 dec places). It's later subclassed into LatField and LonField so I can enter latitudes and longitudes into an application. When I put a LatField or a LonField into my dialog's JPanel, tabbing through the various components in the larger panel shifts the focus to the whole LatField (or LonField) object first, then through the subobjects in the *Field.  How can I get the focus traversal to NOT focus on the DmsField itself, but to go straight to the first component inside the DmsField?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I have tried putting a FocusListener on the JPanel which would set the focus to its first component. Works fine tabbing forward, but gets stuck on first component when back-tabbing.
    Disabling FOCUS_EVENT_MASK on the JPanel didn't change anything.
    The odd thing is, I don't see any other JPanels exhibiting this behavior.

  • Re-order components in JPanel using Drag and Drop

    Hi,
    I have a JPanel that contains some more JPanels (the Layout is GridBagLayout - one column, each row - 1 JPanel). I would like to drag one JPanel (1) and after dropping it on some other JPanel (2), the (1) should be inserted at (2)'s position.
    I really can't get the idea from sun's tutorials :(

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DragTest extends JPanel
        public DragTest()
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weighty = 1.0;
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            for(int j = 0; j < 4; j++)
                JPanel panel = new JPanel(new BorderLayout());
                panel.setBorder(BorderFactory.createEtchedBorder());
                panel.add(new JLabel("panel " + (j+1), JLabel.CENTER));
                add(panel, gbc);
        public static void main(String[] args)
            DragTest test = new DragTest();
            DragListener listener = new DragListener(test);
            test.addMouseListener(listener);
            test.addMouseMotionListener(listener);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class DragListener extends MouseInputAdapter
        DragTest dragTest;
        Component selectedComponent;
        GridBagConstraints constraints;
        Point start;
        boolean dragging;
        final int MIN_DRAG_DISTANCE = 5;
        public DragListener(DragTest dt)
            dragTest = dt;
            dragging = false;
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            Component[] c = dragTest.getComponents();
            for(int j = 0; j < c.length; j++)
                Rectangle r = c[j].getBounds();
                if(r.contains(p))
                    selectedComponent = c[j];
                    start = p;
                    dragging = true;
                    break;
        public void mouseReleased(MouseEvent e)
            if(dragging)  // no component has been removed
                dragging = false;
                return;
            Point p = e.getPoint();
            if(!dragTest.getBounds().contains(p))  // out of bounds
                // failed drop - add back at index = 0
                dragTest.add(selectedComponent, constraints, 0);
                dragTest.revalidate();
                return;
            Component comp = dragTest.getComponentAt(p);
            int index;
            if(comp == dragTest)
                index = getDropIndex(dragTest, p);
            else  // over a child component
                Rectangle r = comp.getBounds();
                index = getComponentIndex(dragTest, comp);
                if(p.y - r.y > (r.y + r.height) - p.y)
                    index += 1;
            dragTest.add(selectedComponent, constraints, index);
            dragTest.revalidate();
        private int getDropIndex(Container parent, Point p)
            Component[] c = parent.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j].getY() > p.y)
                    return j;
            return -1;
        private int getComponentIndex(Container parent, Component target)
            Component[] c = parent.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j] == target)
                    return j;
            return -1;
        public void mouseDragged(MouseEvent e)
            if(dragging)
                if(e.getPoint().distance(start) > MIN_DRAG_DISTANCE)
                    // save constraints for the drop
                    GridBagLayout layout = (GridBagLayout)dragTest.getLayout();
                    constraints = layout.getConstraints(selectedComponent);
                    dragTest.remove(selectedComponent);
                    dragging = false;
                    dragTest.revalidate();
    }

  • How to change properties or add components in JPanel after initialization ?

    Hi,
    I am working on an applet where an image will be loaded in a JPanel from an URL. The JPanel is inside a JscrollPane.
    1.The image will be added on the JPanel later , not during initialization.
    2. JPanel size will be the size of the image.
    3 .the image size may change when the image is changed. Then the JPanel size also has to be updated.
    FYI I am using MediaTracker to load the image.
    I was trying updateUI() for scrollPane. But it is not working.
    How can I do it? Any suggestion?
    Thanks in advance.

    I have to use JPanel because I need flexible control on the imageYou said previously that the panel was the size of the image, so I don't understand what kind of flexible control you are talking about. Presumably you have code in the paintComponent(...) method of the JPanel something like:
    g.drawImage(0, 0, width, height)
    Well that is exactly what a JLabel would do.
    So if you need further custom painting then you would just override the paintComponent(...) method of JLabel to do your custom painting.

  • Click event on Button causes components to shift right.

    I have a pretty basic photo viewer app. When I click on the 'next' button all the components shift to the right a small, but noticeable amount. When I click the 'previous' button the app does not drift either way immediately. If I click previous twice and then next once it has a cummulative effect of moving the components left 1 space. I have never seen this happen before. Any thoughts?
    < mx:Application >
    <mx:HBox>
    <mx:VBox>
    <mx:Button id="prvBt"  click="prevGroup();"
      upSkin="@Embed(source='prev.png')"
          overSkin="@Embed(source='prev_over.png')"
                  downSkin="@Embed(source='prev.png')"
      icon="@Embed(source='prev.png')" >
    </mx:Button>
    <mx:TileList width="120" id="photoList"  height="475" >
    <mx:itemRenderer>
    <mx:Component>
    <mx:Image
    horizontalAlign="center"
    verticalAlign="center"
    source="{data.filename}"
    toolTip="{data.name}"
    width="100"
    height="150" />
    </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>
    <mx:Button id="nxtBt" click="nextGroup();"
    upSkin="@Embed(source='next.png')"
        overSkin="@Embed(source='next_over.png')"
            downSkin="@Embed(source='next.png')"
            icon="@Embed(source='next.png')" >
    </mx:Button>
    </mx:VBox>
    <mx:VBox>
    <mx:ProgressBar id="progressBar" source="{image}" visible="false" />
    <mx:Image width="640" height="474" id="image" source="{photoList.selectedItem.filename}"
    horizontalAlign="center" verticalAlign="center"
    open="progressBar.visible=true" complete="progressBar.visible=false" />
    </mx:VBox>
    </mx:HBox>
    </mx:Application>

    Here is the method in question.
    endRec, STEPVAL, startRec, X are all integers.
    The purpose is to load the next 4 photos in a tilelist component, the photo data is coming from an xml file.
    private function nextGroup():void{
    endRec = endRec + STEPVAL;
    startRec += STEPVAL;
    x = startRec;
    if(endRec > totalRec)
    endRec = totalRec;
    if(startRec < STEPVAL)
    prvBt.enabled = false;
    else
    prvBt.enabled = true;
    if(endRec >= totalRec)
    nxtBt.enabled = false;
    else
    nxtBt.enabled = true;
    tempPhotos.length = 0;
    try{
    while(x < endRec){
    var po:PhotoObject = new PhotoObject();
    po.name = photoFeed.photo[x].@name;
    po.filename = photoFeed.photo[x].@filename;
    tempPhotos.push(po);
    x++;
    photoList.dataProvider = tempPhotos;
    }catch(err:Error){
    Alert.show("a Next Error: " + ObjectUtil.toString(err));

  • Make components like JPanel / Containers ..  from a String..

    public class PuzzlePieces {
         private String area;
         private String *container* = area +"Container";
         private String panel = area +"Panel";
         private Container *container* = new Container();
         private int number;
         public PuzzlePieces(String area, int numbersOfPices) {
              this.area = area;
              this.number = numbersOfPices;
         }as you can see I want to make a Container out of a Sting. How can I do this? Please make an example if you have a solution. TY

    Plexus81 wrote:
    OK, I'll try to explain ..
    I get a string in, as you can see. I want to make/add JButton, JPanel, Containers .. based on name of the String I get in.
    String
    StringPanel
    StringContainer
    But I cant write like this
    Container String +"Container" = new Container();What's the best way to solve this..You want the variable names for those Containers to be based off the Strings? Is that what you mean? Why do you want/need to do that?
    The go-to solution for stuff like this is to use a Map of String, Container pairs. But why over complicate your program with stuff you probably don't really need?

Maybe you are looking for

  • Mutidimensional model does not generate any ddl

    After building a model logical-relational and them adding the multidimensional on that.... selecting the engineer to oracle model only seems to update the colors in the relational and logical views. generating ddl does not add any dimension type ddl.

  • I've got a 4 months dv7, and it overheats badly

    it is not dirty, and to be sincere, i think it's vent system was very poorly designed, and warranty does not apply because the computer is not broken, but i bought a quite high performance machine just to realize i can't use it. Some people recommend

  • Auto update GUI from server

    Goodmorning, i have installed over server "SAP Setup Administrator server" for mantain a gui with centralized deployment. I do some upgrade to packages. For put this new version of package i see in documentation that i must insert an "SAP Automatic s

  • Itunes crashes when trying to turn on genius

    well I just changed my pc. And everytime I try to turn on genius iTunes crashes. Already tried reinstalling and no luck. Do someone knows how to fix this? (iTunes 11.1.2.31 Windows 8)

  • Captivate 8: Effects - Responsive

    I am trying to have a fade-in text effect via the "Color Effect" feature; but none of these options (as per screen capture below: "Alpha", "AlphaFromTo", "Set Alpha") are working for me. Any suggestions? David