Zooming a Jpanel that contains Jbutton

My question is how to zoom a jpanel that contains several jbutton... I am not sure what method to use.... when using a Graphics2D object there seem to be only methods as g.drawString(...)
g.drawRectangle(..) etc... I am kind of familiar with
AffineTransform, scaling matrix, etc but not how to zoom a jpanel with jcomponent...
I hope some one out there understand what i am trying to do...please could you give me any idea
thanx

Hello.
The solution could be the following:
1. Create interface ZoomPane with the following methods:
boolean isZoomMode
float getZoomFactor
2. ZoomPane interface must be implemented by some JComponent (JPanel will fit, assume it's called JZoomPanel)
3. the paint method's body of the JZoomPanel should looks like:
Graphics2D g2 = (Graphics2D)g;
if(isZoomMode()){
float zoomFactor = getZoomFactor();
g2.scale(zoomFactor, zoomFactor);
super.paint(g);
4. Use updated RepaintManager.
This solution solve all painting problem. The mouse event transformation problem can be solved as described above (by means of the glass pane).

Similar Messages

  • Zooming a jpanel containing several jbuttons

    My question is how to zoom a jpanel that contains several jbutton... I am not sure what method to use.... when using a Graphics2D object there seem to be only methods as g.drawString(...)
    g.drawRectangle(..) etc... I am kind of familiar with
    AffineTransform, scaling matrix, etc but not how to zoom a jpanel with jcomponent...
    I hope some one out there understand what i am trying to do...please could you give me any idea
    thanx

    hi again
    well that is the point i have written such sub class where i draw a rectangle and then I scale it etc..
    to test paint () etc but that is what i do not want to ....
    what I want to do is to draw is my subclass of Jbutton that has some specific properties I HAVE TO USE THEM... and only zoom these specific button and not everything else on my subclass of Jpanel...
    Spanel extends JPanel
    MybuttonClass m = new MybuttonClass();
    paint()
    how do I draw the myButton on the panel...after zooming in zoomin out...
    there no such thing
    g.draw(myButton);
    does all this make a sense to you..
    i hope so
    thanx

  • PropertyChangeListener for a JButton that contains a JPanel?

    I created a class that extends from the JButton class. The class contains a JPanel that adds two components to the panel, A JLabel that contains text and a JLabel that contains an icon. Therefore this class is really just a button that contains a JPanel with 2 JLabels added to the panel. (Reason for doing this is it adds layout control to add the 2 components to a panel instead of directly to the JButton) Normally you would do a changepropertylistener to the JButton but because I added the 2 components (JLabel) to a panel and then added the JPanel to the button, the button doesn't notice any change events. How would I detect the PropertyChangeEvent for this cenario?
    thanks,
    Peter Landis

    The solution to the problem is when the instance of the class is created, do a getComponent(0) to get the JPanel component and the do a getComponent(0) to get the JLabel component. Now from here you can add a PropertyChangeListener to the JLabel that you just obtained. The PropertyChangeListener class will look like:
    class RotorItemListener implements PropertyChangeListener
         public void propertyChange(PropertyChangeEvent e)
    System.out.println("CHANGE");
    String name = e.getPropertyName();
    if(name == "text")
    System.out.println("Label changed");
    This will only trap a change that occurs when the label has changed. If you omit the if(name == "text") then when the component is created, a property change event will be triggered which is not what you want. This only traps event that occur only when a change has occurred on the JLabel. Notice that during the instantiation of the component you'll see the text displayed "CHANGE" and not the "Label changed" until the label text has changed.
    Pretty cool huh!

  • JPanel that close the parent JFrame

    Hello.
    I'm puzzled... how can I close a JFrame from the JPanel it contains?
    I mean:
    I have a Form that extends JFrame. In this form there's a JPanel, which has a BorderLayout. In the South part of the BorderLayout there's a JPanel (BoxLayout) that contains a JButton.
    I'd like this JButton to get disposed of the Form.
    How should I?
    Is there a better way to manage with this?
    (putting the button somewhere else...)
    Thank you

    Sorry, I forgot to mention that my sub-panel is in another class, another file.
    So I don't know how to call the parent frame.
    I tried with some .getParent(), but I get
    JPanel
    JLayerPane
    JRootPane
    and no JFrame.
    I could just put everything into 1 single class (or inner classes at least), but if there's a chance to keep them in different files, I would be glad to learn about it :)
    Thank you.

  • FlowLayout in JPanels, and Container

    I set the FlowLayout alignment to RIGHT justify on my Container. I also want to control individual FlowLayouts in JPanels that are added to the Container. I want some panels to be center, and others LEFT or LEADING alignments, etc.
    So far everything I try on the JPanel LayoutManager Alignment has no effect. Only the changes I make to the Container layout alignment have an effect. All of the JPanels are RIGHT justified when I run this program.
              rightLayout = new FlowLayout();
              rightLayout.setAlignment(FlowLayout.RIGHT);
              centerLayout = new FlowLayout();
              centerLayout.setAlignment(FlowLayout.CENTER);
              leftLayout = new FlowLayout();
              leftLayout.setAlignment(FlowLayout.LEADING);
              container.setLayout(rightLayout);
              titlePanel = new JPanel(centerLayout);
              twoPanel = new JPanel();
              threePanel = new JPanel(leftLayout);
              fourPanel = new JPanel();
              text1Panel = new JPanel(centerLayout);
              text2Panel = new JPanel(centerLayout);
              buttonPanel = new JPanel(centerLayout);
    Thanks, rjw

    Okay i think that to use GrisBagLayout takes away all the hastle,you can get things where you want them,
    i think people don't use cause it seems like it's more complex to use,if you put this helper method in your code then you only need one line in your code to place a component.
    This is the line of code to place a component
            addComp(theButton,theContainer,gb1,gbc,       0,1,1,1,1,1,gbc.WEST);Place this at the start of your CODE also
             GridBagLayout gb1 = new GridBagLayout();
             GridBagConstraints gbc = new GridBagConstraints();
             setLayout(gb1);/*
         * This is a helper method for GridBagConstraint Layout
         public void addComp(Component comp,Container cont, GridBagLayout gb1,GridBagConstraints gbc,
                        int row,int col, int numRows, int numCols, double weightx, double weighty,int theAnchor)
              gbc.gridx = col;
              gbc.gridy = row;
              gbc.gridwidth = numCols;
              gbc.gridheight = numRows;
              gbc.weightx = weightx;
              gbc.weighty = weighty;
                                               gbc.anchor = theAnchor
              cont.add(comp,gbc);
         }If you try and understand and it's not quite hard then it makes GUI building a lot easier and more efficient i think,let me know if you give this a go.

  • Listener of a JPanel that listens to events of its components

    Is there a listener (that I can add to a JPanel) that listens to events generated by the panel's components?
    Award: 2 duke stars

    Well it ought to.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained,
    Compilable and Executable, Example Program that demonstrates the
    incorrect behaviour, because I can't guess exactly what you are doing
    based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its
    original formatting.

  • Extending JPanel to contain a JRootPane - problems with scroll panes

    I am trying to write a JPanel subclass that contains a JRootPane, similar to the way that JFrame contains a JRootPane. The reason that I am doing this is that I would like to be able to intercept mouse events using the JGlassPane facility, but adding the glasspane to the JFrame is problematic since it then intercepts mouse events over all components in the JFrame, including the menu bar. It seems simpler to me to have the JRootPane owned by a JPanel, to give me better control over intercepting events. I've got an implementation working with the JFrame case, but have had to handle many small "gotchas", and at least one more exists. I'm hoping to simplify things by moving away from this way of doing things.
    I wrote a straightforward RootPanePanel class that extends JPanel and implements RootPaneContainer, delegating all of the add methods to the JRootPane's content pane. Here's the constructor for RootPanePanel:
    public RootPanePanel (LayoutManager layout) {
            rootPane = new JRootPane ();
            rootPane.setOpaque(true);
            rootPane.getContentPane().setLayout(layout);
            super.add (rootPane);
    }RootPanePanel also delegates calls like getContentPane/setContentPane to the JRootPane.
    To test my implementation, I wrote a main method that looks like the following:
    public static void main (String[] args) {
      SwingUtilities.invokeLater(new Runnable () {
        public void run () {
          try {
            JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
            JScrollPane scrollPane = new JScrollPane (editorPane);
            JFrame frame = new JFrame ("Test RootPanePanel");
            RootPanePanel panel = new RootPanePanel ();                    
            panel.add(scrollPane);
            frame.add(panel, BorderLayout.CENTER);
            scrollPane.setPreferredSize(new Dimension(800, 600));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize (640, 480);
            frame.pack ();
            frame.setVisible(true);
          } catch (Exception e) {
            e.printStackTrace();
      });Note that I'm not actually using JEditorPane in my application, but it is the simplest component that displays the problem I'm encountering.
    When this code runs, it is fine, as long as the JFrame is big enough to display the scrollbars for the JScrollPane. If the JFrame is made small enough, the scrollbars are not displayed.
    If I instead add the JScrollPane to the JFrame directly, it behaves as you would expect.
    Is this a problem of mixing heavyweight and lightweight components? It doesn't seem like it should be; in both cases the JScrollPane is handling the same client component, the JEditorPane.
    Any suggestions/ideas are welcome!

    Here's the full RootPanePanel class in case people want to try it out
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.HeadlessException;
    import java.awt.LayoutManager;
    import java.io.IOException;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    import javax.swing.JRootPane;
    import javax.swing.JScrollPane;
    import javax.swing.RootPaneContainer;
    import javax.swing.SwingUtilities;
    public class RootPanePanel extends JPanel implements RootPaneContainer {
         private JRootPane rootPane;
         public RootPanePanel () {
              this (new BorderLayout());
         public RootPanePanel (LayoutManager layout) {
              rootPane = new JRootPane ();
              rootPane.setOpaque(true);
              rootPane.getContentPane().setLayout(layout);
              super.add (rootPane);
         public Container getContentPane() {
              return rootPane.getContentPane();
         public Component getGlassPane() {
              return rootPane.getGlassPane();
         public JLayeredPane getLayeredPane() {
              return rootPane.getLayeredPane();
         public void setContentPane(Container arg0) {
              rootPane.setContentPane(arg0);
         public void setGlassPane(Component arg0) {
              rootPane.setGlassPane(arg0);
         public void setLayeredPane(JLayeredPane arg0) {
              rootPane.setLayeredPane(arg0);
         @Override
         protected void addImpl(Component comp, Object constraints, int index)
              if (comp == rootPane) {
                   super.addImpl(comp, constraints, index);
              else {
                   getContentPane().add(comp, constraints, index);
         @Override
         public Component add(Component comp, int index) {
              return rootPane.getContentPane().add(comp, index);
         @Override
         public void add(Component comp, Object constraints, int index) {
              rootPane.getContentPane().add(comp, constraints, index);
         @Override
         public void add(Component comp, Object constraints) {
              rootPane.getContentPane().add(comp, constraints);
         @Override
         public Component add(Component comp) {
              return rootPane.getContentPane().add(comp);
         @Override
         public Component add(String name, Component comp) {
              return rootPane.getContentPane().add(name, comp);
         public static void main (String[] args) {
              SwingUtilities.invokeLater(new Runnable () {
                   public void run () {
                        try {
                             JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
                             JScrollPane scrollPane = new JScrollPane (editorPane);
                             JFrame frame = new JFrame ("Test RootPanePanel");
                             RootPanePanel panel = new RootPanePanel ();                    
                             panel.add(scrollPane);
                             frame.add(panel, BorderLayout.CENTER);
                             scrollPane.setPreferredSize(new Dimension(800, 600));                                                                                                                                                 
                             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                             frame.setSize (640, 480);
                             frame.pack ();
                             frame.setVisible(true);                                                                                                    
                        } catch (HeadlessException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
         public JRootPane getRootPane() {
              return rootPane;
    }

  • How do I assign a file to a drive other than the drive that contains my program software?

    I've just installed a video editing program on my new Mac Pro Xeon 64 bit workstation. I want to ensure that all my media files reside on a drive other than the drive that contains programs. I had no problem doing this on my old Dell. How do I do this on my Mac Pro? -- Gary

    Application Preferences.
    Next time, 'what' program would also help.
    Most people do setup with a dedicated boot drive with OS and apps, .then use other drives or array(s) for media, scratch as needed, including external hardware RAID.

  • My playlists in itunes that contained voice memos are now blank on my phone, yet they are still on the playlist in itues on my computer. any ideas

    my playlists in itunes that contained voice memos are now blank on my phone, yet they are still on the playlist in itues on my computer. any ideas
    i like to record concerts i go to a listen to them and the voice memos are how i record them

    If you still have the 'pointers' to them in iTunes then I think that it assumes that you still have them on your computer so it won't re-download them or let you copy them from your iPod - try deleting the iTunes entry for one of them and then re-try re-downloading or, with your iPod connected, File > Transfer Purchases. If it works for that one then do the same for the others.

  • How to find a polygon that contains a point

    I have a table that has the boundaries (polygones) for all the zip codes in my state and I want to find the zip code that contains the given LON/LAT
    The following query is aparently not valid:
    SELECT *
    FROM ZIP_BOUNDARY b
    WHERE sdo_relate(b.geom, SDO_POINT_TYPE(-122.079155, 37.392892, NULL),'mask=touch') = 'TRUE'
    WHERE sdo_relate(b.geom, SDO_POINT_TYPE(-122.079155, 37.392892, NULL),'mask=touch') = 'TRUE'
    ERROR at line 5:
    ORA-29900: operator binding does not exist
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'SDO_RELATE'
    What is the correct way to write such a query?

    try the following:
    SELECT *
    FROM ZIP_BOUNDARY b
    WHERE sdo_relate(b.geom, sdo_geometry(2001, YOUR_SRID, SDO_POINT_TYPE(-122.079155, 37.392892, NULL), NULL, NULL), 'mask=CONTAINS') = 'TRUE';

  • When i update to the latest version (7.0.3), there is a message appear to me when i open any application that contains notification such as (What'sApp or BBM),this message said (Connect to iTunes to use push Notification),How I can to stop these message?

    When i update to the latest version (7.0.3), there is a message appear to me when i open any application that contains notification such as (What'sApp or BBM) , this message said (Connect to iTunes to use push Notification) , How I can to stop these messages that appear to me constantly?

     Hi,
    One of my ex-colleagues has installed a NI-DAQ 6.5 in our system. [And I do not see any other naitional instruments card in the CPU of the computer, may be he removed it] I deleted the account and all his files in the system. When I am trying to install version8.0, its not getting installed and giving me a message that I should uninstall the previous version by going to Add/Remove programs in the control panel.
    I tried doing that, but the "Change/Remove" button does not seem to work...[There is no response and so unable to install the new version...]
    Any idea how can this problem be solved?
    It is a windowsXP operating system with SP2 installed on a machine with P4 processor.
    Thanks

  • An older style Ipod has over 10,000 songs on it.  The original computer that contained these songs on itunes has since been replaced.  Can itunes/match get the songs from this ipod to store in match and then put on new computer/itunes?

    Can this new service of itunes/match allow you to retrieve songs from an older style ipod, store them in match, and then download them onto a new computer/itunes?  The original computer that contained these songs has since been replaced b/c it broke down.  There were alot of songs on there and now I can't get the songs onto my new computer.  Can match work from ipod > match > computer?

    sharwilly wrote:
    Can this new service of itunes/match allow you to retrieve songs from an older style ipod
    Only if it is an iPod touch that you can turn on iTunes Match.
    The original computer that contained these songs has since been replaced b/c it broke down. 
    Did you make a backup of all the  important files on this computer before it broke down?
    Try this -> http://www.yamipod.com/main/modules/home/
    Then backup your computer after you recover the items.

  • How can I list all folders that contain files with a specific file extension? I want a list that shows the parent folders of all files with a .nef extension.

    not the total path to the folder containing the files but rather just a parent folder one level up of the files.
    So file.nef that's in folder 1 that's in folder 2 that's in folder 3... I just want to list folder 1, not 2 or 3 (unless they contain files themselves in their level)

    find $HOME -iname '*.nef' 2>/dev/null | awk -F '/'   'seen[$(NF-1)]++ == 0 { print $(NF-1) }'
    This will print just one occurrence of directory
    The 'find' command files ALL *.nef files under your home directory (aka Folder)
    The 2>/dev/null throws away any error messages from things like "permissions denied" on a protected file or directory
    The 'awk' command extracts the parent directory and keeps track of whether it has displayed that directory before
    -F '/' tells awk to split fields using the / character
    NF is an awk variable that contains the number of fields in the current record
    NF-1 specifies the parent directory field, as in the last field is the file name and minus one if the parent directory
    $(NF-1) extracts the parent directory
    seen[] is a context addressable array variable (I choose the name 'seen'). That means I can use text strings as lookup keys.  The array is dynamic, so the first time I reference an element, if it doesn't exist, it is created with a nul value.
    seen[$(NF-1)] accesses the array element associated with the parent directory.
    seen[$(NF-1)]++ The ++ increments the element stored in the array associated with the parent directory key AFTER the value has been fetched for processing.  That is to say the original value is preserved (short term) and the value in the array is incremented by 1 for the next time it is accessed.
    the == 0 compares the fetched value (which occurred before it was incremented) against 0.  The first time a unique parent directory is used to access the array, a new element will be created and its value will be returned as 0 for the seen[$(NF-1)] == 0 comparison.
    On the first usage of a unique parent directory the comparison will be TRUE, so the { print $(NF-1) } action will be performed.
    After the first use of a unique parent directory name, the seen[$(NF-1)] access will return a value greater than 0, so the comparison will be FALSE and thus the { print $(NF-1)] } action will NOT be performed.
    Thus we get just one unique parent directory name no matter how many *.nef files are found.  Of course you get only one unique name, even if there are several same named sub-directories but in different paths
    You could put this into an Automator workflow using the "Run Shell Script" actions.

  • How can I find an ID file that contains a text...?

    I've been working with InDesign for a long time. So, I have a lot of .indd files, from version 1 up to CS3.
    I need to find a file(s) that contains a specific text. E.g. the name of a person, that I'm sure is somewhere in my thousands of ID files.
    It's impossible to open all the files until I locate that text.
    In Windows Explorer, there's a way to search a word or phrase in a file, but it only returns doc, txt, rft, and other text files, even pdf. But not indd.
    Can somebody help me, please?
    Thanks,
    Hirao

    Have you tried changing the extension on your .indd files to .txt? It's
    a binary format, but there's a lot of plain text in there. The name
    you're looking for, or part of it, is probably in there somewhere.
    Search for the shortest possible text string. Some words are not continuous.
    Kenneth Benson
    Pegasus Type, Inc.
    www.pegtype.com

  • Is there a way to create a smart folder in iTunes, that contains the most recent (say 10) used playlists?

    Is there a way to create a smart folder in iTunes, that contains the most recent (say 10) used playlists? By having this I would be three clicks (touches from what is recent).
    Thanks

    100s with about 30 folders, comprised on different moods, years, genre, favorites, audiobooks, podcasts. Being accessed from multiple Macs and Apple TVs.

Maybe you are looking for

  • Changing text into dunning letter

    Hi I am trying to change some std text in the dunning letter. But we have some customized form/script for this and not using the std one.And for some reason i am not able to find that form/script.. Could somebody please help me in finding the actual

  • How do I get two displays to work on Macbook Pro 13 inch?

    I have my laptop hooked to a Thunderbolt Display and then I have a second monitor hooked through a mini-display port to DVI adapter plugged into the back of the Thunderbolt display. When I go into Display I only see one monitor. I don't see a detect

  • Processing cyrilic input from HTML FORM

    Hello everybody, I have faced the problem with processing the cyrilic input from the HTML form, The JSP code to receive it and store it can`t do it properly. The <page> directive has ContentType='text/html; charset=UTF-8' and the HTML itself has <met

  • Delete multiple master images: hangs

    When I choose multiple images for delete I get the infinite spinning beach ball. I searched for similar posts and did not find anyone with the same problem. Deleting one image at a time works ok. I have to force quit and restart. When the project is

  • String values in JSlider

    Hi, I need to put the string values in the JSlider. For integer values i can use the constructor JSlider (int nMin, int nMax). Suppose i use JSlider (0, 100), then JSlider values ranges from 0 to 100. I need JSlider, containing three string values(lo