How to extend a jpanel

hi
this might sound like a beginers question
i have a main class which extends jframe i called the frame graphicsframe i have also decleared, a jpanel inside
this class.
but how do i extend that JPanel in another class i know you can use graphicsframe.panel to change the methods. but then i have to declear all of the methods using graphicsframe.panel.

to extend a JPanel you simply, ... extend it:
public class MyPanel extends JPanel
  // you'll need a constructor or a few in here plus any override and new methods
}I try to avoid extending JPanels, JFrames, and whatnot unless I'm going to change the basic behavior of the component, most commonly to override the paintComponent of a JPanel so I can draw in it.
By the way, what is to "declear"?
One more point: you probably should post Swing questions in the Swing forum (but please don't do this now. Continue on with this thread and please don't cross-post).

Similar Messages

  • How to make a JPanel selectable

    When extending a JPanel and overriding the paintComponent() method the custom JPanel can not be selected so that it gets for example KeyEvents.
    But if I make the new Class extend a JButton it gets of course selected and able to receive for example KeyEvents.
    My question is therefore; what does the JButton implement that a JPanel doesn’t so that a JButton gets selectable? Or in other words; how to make a JPanel selectable?
    Aleksander.

    Try this extended code. Only the first panel added can get the Focus.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Test extends JFrame
      public Test()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel1 = new JPanel(new BorderLayout());
        JPanel panel2 = new JPanel(new BorderLayout());
        ImagePanel imgPanel = new ImagePanel();
        panel1.setFocusable(true);
        panel2.setFocusable(true);
        panel1.setPreferredSize(new Dimension(0, 50));
        panel2.setPreferredSize(new Dimension(0, 50));
        panel1.setBorder(BorderFactory.createLineBorder(Color.RED,     4));
        panel2.setBorder(BorderFactory.createLineBorder(Color.CYAN,    4));
        imgPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 4));
        panel1.add(new JLabel("Panel 1"), BorderLayout.CENTER);
        panel2.add(new JLabel("Panel 2"), BorderLayout.CENTER);
        getContentPane().add(panel1, BorderLayout.NORTH);
        getContentPane().add(panel2, BorderLayout.SOUTH);
        getContentPane().add(imgPanel, BorderLayout.CENTER);   
        pack();
        panel1.addKeyListener(new KeyAdapter(){
            public void keyPressed(KeyEvent ke){
                System.out.println("Panel1");}});
        panel2.addKeyListener(new KeyAdapter(){
            public void keyPressed(KeyEvent ke){
                System.out.println("Panel2");}});
      public static void main(String[] args){new Test().setVisible(true);}
    class ImagePanel extends JPanel
      Image img;
      public ImagePanel()
        setFocusable(true);
        setPreferredSize(new Dimension(400,300));
        try{img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif"));}
        catch(Exception e){/*handled in paintComponent()*/}
        addKeyListener(new KeyAdapter(){
          public void keyPressed(KeyEvent ke){
            System.out.println("ImagePanel");}});
      public void paintComponent(Graphics g)
        if(img != null)
          g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
        else
          g.drawString("This space for rent",50,50);
    }

  • How To Extend Adobe Audition CS5.5

    I've received a number of questions on how to extend Adobe Audition with questions similar to:
    How do I import file format X?
    How do I import a project from application Y?
    Will there be an SDK available?
    How do I add plug-ins to Audition?
    I had made a post similar to this in the public beta of Audition for Mac, but I can no longer find the thread. So I'll reiterate some stuff here:
    Area
    Info
    Adding VST Plug-Ins
    Most of you have found this already, but the best place to start is in the Audio Plug-In Manager
    If you want to "write" new plug-ins for Audition, writing a VST plug-in will be the best option as it will allow you to write something that will work on Windows as well as OSX.  Info on writing a VST plug-in may be found here (http://www.steinberg.net/en/company/developer.html)
    Adding Audio Unit Plug-Ins (Mac OSX)
    Same as Above.   Note that OSX ships with some built-in AU plug-ins that Audition can utilize for free if you just scan at least once.   We don't scan on startup because there's several plug-ins out there in the world that don't behave well.  Info on Audio Unit plug-in development can be found here (http://developer.apple.com/library/mac/#documentation/MusicAudio/Conceptual/AudioUnitProgr ammingGuide/TheAudioUnit/TheAudioUnit.html)
    Adding more import formats via libsndfile
    libsndfile is an open-source C library for reading and writing audio files (http://www.mega-nerd.com/libsndfile/)   Ambitious people could download the source, write support for another format, and create their own custom-rolled library of libsndfile.  You would then replace the version of libsndfile with which Audition CS5.5 ships, with the one you rolled.   Due to the way we use libsndfile, any format you add would show up in Audition.   This is also true if there's an official update to libsndfile that comes out in the future, you could just plop it in and it should work. 
    If you're interested in exporting or writing formats that libnsdfile supports, please tell us which formats are the most important to you and in what way you use them in your workflow.
    Adding more import formats via QuickTime components
    QuickTime has the ability to be extended via QuickTime Components.   There's several examples out there, but here are some websites to check out:
    QuickTime Components (http://www.apple.com/quicktime/resources/components.html)
    Learn about even more QuickTime capabilities (http://www.apple.com/quicktime/extending/components.html)
    Flip4Mac for Windows Media support on OSX (http://www.telestream.net/flip4mac-wmv/overview.htm)
    Perian -- the swiss-army knife for QuickTime (http://perian.org/)
    Calibrated Software (http://www.calibratedsoftware.com/products.asp)
    In most cases, just adding the various QuickTime components will automatically add the import functionality to Audition.
    Importing project formats from other applications
    As seen on other threads in this forum, Ses2sesx (http://www.aatranslator.com.au/ses2sesx.html) and AATranslator (http://www.aatranslator.com.au/) seem to add quite a bit of support.
    SDK
    At this time, we haven't released an SDK for Audition.   If you're interested in one, however, please tell us what you would want from an SDK for Audition and we'll take it into consideration.
    Message was edited by: Charles VW
    Added links to AU and VST development info

    Charles,
    could you please also advise what PC users can do to make common avi files useable in AA CS5.5? The obvious problem is, no matter how many exotic video formats a PC can play by way of video-for-windows codecs, these are useless for Quicktime, because Quicktime on the PC needs codecs specifically written for "Quicktime for Windows", which are, as I've come to find, EXTREMELY rare. So far I've only found ONE, sold by 3ivx, but this costs as much as the AA CS5.5 update itself. Without them, Quicktime on the PC will only handle mov files, which are not too popular on the PC. Is there any other way out of this?

  • How to dynamically resize JPanel at runtime??

    Hello Sir:
    I met a problem, I need to resize a small JPanel called panel within a main Control JPanel (with null Layout) if I click the mouse then I can Drag and Resize this small JPanel Border to the size I need at runtime, I know I can use panel.setSize() or panel.setPreferredSize() methods at design time,
    But I have no idea how to do it even I search this famous fourm,
    How to dynamically resize JPanel at runtime??
    Can any guru throw some light or good example??
    Thanks

    Why are you using a null layout? Wouldn't having a layout manager help you in this situation?

  • How to place a JPanel at the center of another JPanel?

    Can anyone tell me how to place a JPanel inside another JPanel? The first JPanel consists of three JPanels each consisting of a label&textfield and are placed using BoxLayout. The second JPanel is a big blank screen. So, i would like to put the first JPanel at the center of second JPanel(horizontally & vertically). The problem is that i don't have any other component. So,if i try to use FlowLayout, i am able to put it at the center(horizontally, not vertically) only on the top edge. I tried to use BoxLayout. But, i couldn't(as i don't have any other elements). I tried to create some blank elements. But, they are messing up the elements of my JPanel. Any cluesssssssss??????????

    import java.awt.*;
    import javax.swing.*;
    public class CenteredLayout
        private JPanel getPanel()
            GridBagLayout gridbag = new GridBagLayout();
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            JPanel p = new JPanel(gridbag);
            addComponents(new JLabel("label 1"), new JTextField(8), p, gbc);
            addComponents(new JLabel("label 2"), new JTextField(8), p, gbc);
            addComponents(new JLabel("label 3"), new JTextField(8), p, gbc);
            JPanel panel = new JPanel(gridbag);
            panel.setBackground(Color.pink);
            gbc.anchor = GridBagConstraints.CENTER;
            gbc.insets = new Insets(0,0,0,0);
            panel.add(p, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc)
            gbc.anchor = GridBagConstraints.EAST;
            gbc.gridwidth = GridBagConstraints.RELATIVE;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            c.add(c2, gbc);
        public static void main(String[] args)
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new CenteredLayout().getPanel());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    }

  • Hi i would like to know how to extend the range of my time capsule wifi network(500G 802.11n) using an airport express. i have a double storey home and would like to extend range to my upstairs bedrooms.i have a time capsules network setup via a netgear a

    hi i would like to know how to extend the range of my time capsule wifi network(500G 802.11n) using an airport express. i have a double storey home and would like to extend range to my upstairs bedrooms.i have a time capsules network setup via a netgear adsl.i have a second imac upstairs which connects to time capsule wifi network (it is within range as it is directly abobe on 1st floor)
    could you tell me how best to set airport express up to extend my wifi range?

    Greetings,
    This is called an "Extended wireless network".
    Read this article for details and steps on how to extend your TimeCapsule's network:
    http://support.apple.com/kb/HT4259
    Cheers.

  • How to extend an address of a BP  with more fields ???? EEWB??

    Hi Gurus,
    I need to extend the address of a BP with some customer fields. I have tried to do it using EEWB but when you have to choose a Business Object for the new extension, the reasonable only possibility is to choose BUPA Object. Thus, the DB table BUT000 is extended with a custom include that contains the customer fields, but what I want to do is extending ADRC DB table. There is some way that I do not know of achieve this in which the system creates automatically all the FM for the BDT events????
    If it is not possible, which would be the procedure to do that with my own development???
    Thanks in Advance.
    Regards,
    Rosa

    Rosa, you can only extend table BUP000 and not the actual address table. Sorry for that for more details on how to extend the BP itself refer to my WeBLOG I wrote on this. Have fun and let me know whether you need more help, Tiest.
    Also do not forget to award points to useful responses.
    <a href="/people/tiest.vangool/blog/2005/07/24/pc-ui-and-easy-enhancement-workbench-eew-integration and Easy Enhancement Workbench (EEW) Integration</a>

  • In an inbuild example of can .. that CAN transmit periodic vi .. i am unable to understand how the extended and standard frame is set?

    In an inbuild example of can .. that CAN transmit  periodic vi .. i am unable to understand how the extended and standard frame is set?
    plz help me .. stuck up very badly
    thanks
    mahadev
    Solved!
    Go to Solution.

    I suggest this KB which explains usage of Ext IDs with NI-CAN
    http://digital.ni.com/public.nsf/allkb/2FA120A37EDBC51D86256854004FB0C7

  • Outlook 2013 - How to extend/add new meeting in recurrent meeting inside SharePoint site ?

    I have created a recurrence meeting but now it is exired, how to extend ? Please advise

    Hi,
    Please check the link below
    https://support.office.com/en-us/article/Create-link-to-or-update-Meeting-Workspaces-98834566-4750-45e9-bb71-fe4acb26f170?ui=en-US&rs=en-US&ad=US#BM2
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/01054bef-1cb0-4401-88c9-e4593ab4b806/how-to-extend-date-in-recurring-meeting-workspace-in-sharepoint-site?forum=sharepointgenerallegacy
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • How to extend the range with a second Airport Express? Do I need a DSL cable?

    How to extend the range with a second Airport Express? Do I need a DSL cable?

    Thanks, now we need a bit more information, please, in order to provide you with the correct information that you need.
    I assume that you already have one AirPort Express.....either a model A1264 or A1392.....set up and operating OK, is that correct?
    If yes, you can extend the network either by using wireless or an Ethernet cable with a second AirPort Express.....either the A1264 or A1392 model. A wired connection is the way to go, if possible, since it provides better performance.  But, wireless might work OK for you if you want to try that.
    Let us know "how" you want to extend......wireless or wired?

  • How to extend business partner number length

    My legacy business partner id is 13 digits long. But SAP business partner is only 10 digits long at maximum.
    Please tell me how to extend this constraint?
    Giang

    Hi Giang,
    Unfortunately, this is not possible - you cannot extend the length of BP number.
    But there's a simpler way - there is a field called BPEXT in BUT000, this is the external BP number, and can store 20 digits.
    You can transfer the BP number of legacy system into BPEXT field on the SAP system. This is a standard practice and is used by most people.
    Regards,
    Rishu.

  • How to extend Article to Different Sales organization

    Hi experts
    How to extend Article to Different Sales organization
    thanks in advance

    Hi Hanumant,
    1. Go to MM42
    2. Enter the article to be extended.
    3. Enter the Sales Organization and Distribution Channel to which the article to be extended to.
    4. Select the Sales View.
    5. Press Enter
    Save
    It's Done.
    To verify, goto mm43 and enter the detail and check
    or
    after entering the article code in mm43 go to Sales Org. field and press F4, in the popup you will see a column 'Maint.' , X should be marked in front of your new sales org,dist channel combination.
    Hope it helps.
    Regards,
    Anirban Roy

  • When saving a page under text format, the text is limited to 80 columns only, how to extend to 120 columns

    When I save a page under text format, the text is limited to 80 columns only, how to extend to 120 columns (or more)?

    HI K,
    This is the Numbers (Mac OS) forum. Your question about Numbers for iOS will probably get better results posting in the iWork for iOS area. the link will take you there.
    Regards,
    Barry

  • How to extend same material into different plants?

    Hi all,
    how to extend the same material into different plants anybody please tell me.
    thanks
    s.muthu

    hi
    go to mm01 create a material with name abcd
    then again in mm01 in material filed give same no (abcd)and  in copy from field also give that no(abcd)
    sytem will ask u for from and t locations give that and proceed
    similarly if u want to extend view in the material go to mm50 and do
    reward if helpful
    regards
    kunal

  • How to extend factory calender to a plant ?

    Hi Ranga:
    How to extend factory calender to a plant ? ( Tcode: SCAL, The calender is not client specific)
    I check marked US factory calender, where after can you tell how to extend factory calender to plant
    Note: I am using IDES ( International Demonstration & Education System)
    Thanks

    Hi Sandeep,
    you need to use the following path
    Go to SPRO>ENTERPRISE STRUCTURE->DEFINITION> LOG GENERAL>DEFINE COPY,DELETE AND CHECK PLANT>DEFINE PLANT
    Here you need to assign the factory calendar. The assignment in work center will only applicable for capacity not for MRP and others.
    <b>For information how to create a factory calendar</b>
    Pl follow the steps
    1.Go to SCAL transaction
    2.there will be three options.
    Click first public holidays and go in change mode.
    Click create and create your holidays there and save.(Generally fixed date will be used in the pop up)
    3.Now click Holiday calendar and go in change mode.
    Click create and give holdiay cal id and description.
    Click assign public holiday and add your holidays one by one and save
    Now holiday cal is created.
    4.Now come out and choose fact calendar and go in change mode
    Click create and give Factory calendar id and description, and validity period.
    Give the holiday calendar ID.
    If you want to give special rule like any of the specific date/ day is the holiday or work day (which is different from holiday calendar you can define)
    and save.
    5.You have to assign factory calendar to PLANT
    Go to SPRO>ENTERPRISE STRUCTURE->DEFINITION> LOG GENERAL>DEFINE COPY,DELETE AND CHECK PLANT>DEFINE PLANT
    Choose your plant and go to details-
    You have to define factory calendar there
    Hope this will help you
    Regards
    Ranga

Maybe you are looking for

  • Time Capsule problems solved?

    Hello apple community, I´m a new member of apple family and now I would like to buy a Time Capsule to enlarge my little collection of apple products. But on timecapsule.org and in apple support community I read about the "sudden death" problems. That

  • Background Repeat X feature not working.

    Good day all, hopefully you could help me with this issue. I have a 26 page website that I've just completed and all the pages have varying heights so I simply exported my gradient background from photoshop cs6 as a .png and pressed ctrl+j and insert

  • Why is my gradient in illustrator just black in text?

    Every time I use the gradient tool on text it only shows up black, what's the deal with that?

  • I want to help

    I have a problem in my macbook pro while shutdown it start beef sound and also the key board lights are not working plz help me

  • I think my nano is dead

    Well i just got my Nano and when i opened it it just seemed fine, very fine. So i installed iTunes and stuff and started uploading music. I then went to sleep and in the morning, my nano wouldnt even open. So i tried to reboot that **. The Apple came