Add JPanel on top of a JPanel?

Hi,
I just wonder if I can add a Jpanel on top of a Japnel since when i compile this
it has ava.lang.NullPointerException: peer
     at sun.awt.windows.WCanvasPeer.create(Native Method)
     at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:378)
     at sun.awt.windows.WCanvasPeer.<init>(WCanvasPeer.java:26)
I appreciate if anyone can help
thks
public class MiningBox{
public JInternalFrame newMineFrame(String name) {
JInternalFrame internal = new JInternalFrame(name, true, true, true, true);
internal.setSize(519, 370);
Kmeans k_means= new Kmeans();
internal.setContentPane(k_means);
return internal;
public class Kmeans extends JPanel {
GraphCanvas graphcanvas = new GraphCanvas(this);
Options options = new Options(this);
Panel sbpanel = new Panel();
Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL, graphcanvas.n, 5, 2,
graphcanvas.maxN);
Scrollbar sc = new Scrollbar(Scrollbar.HORIZONTAL, graphcanvas.nbclass,
3, 2, graphcanvas.maxC);
Kmeans(){
setLayout(new BorderLayout(10, 10));
sbpanel.setLayout(new GridLayout(2, 1, 0, 5));
sbpanel.add(sb);
sbpanel.add(sc);
add(BorderLayout.CENTER, graphcanvas);
add(BorderLayout.EAST, options);
add(BorderLayout.SOUTH, sbpanel);
}

Not sure exactly why you're getting this exception. You certainly can add a JPanel into another JPanel.
However, it is generally better not to mix AWT components with Swing components. AWT components are considered 'heavy-weight' components (since they use a native peer to present themselves) while Swing components are 'light-weight' (as they paint themselves based on the look-and-feel). These two types don't usually play well together.
If you can, I would recommend using a JScrollPane instead of the ScrollBar, and you would probably want to convert all of your other AWT components to Swing (ie. JPanel instead of Canvas, JPanel instead of Panel, etc.). Just doing that might clear up the problem.

Similar Messages

  • How to add JPanel in  JComboBox?

    Hi.
    How to add JPanel in JComboBox...?
    Regards
    Bilal

    I do not know much about Cardlayout.
    As far as I know, it is a layout which let you assign a serveral 'card' and exist together. By consider the order of the card, you could change the view of each page by using method- first, last, next etc. However, I would like to know what if I got a number of buttons, say A B C D E F, and having cards called a b c d e f,I know I could change from a to b, but what if I want to change from c to e by pressing the button E (assuming it showing the c card now).
    Actually, I was able to create the code now which adding one JPanel to another now. First create a JPanel with prefer size, min max size.
    then add a JPanel into the CENTER of the above JPanel, both using borderlayout.
    But having a little difficulties, could I add more JPanel into the CENTER such that one overlapping each other, by those Buttons, through action and event, hide those which I do not want to show?
    Like A B C buttons, a b c panels. When press A hide b c and show a, so on.
    Could I use method like movetofront(something like that, forgot detail which read in a book) to do this?
    Cheers

  • Can i add JPanel to Jasper Report

    I have a panel on which I have drawn some graphics and now I want this panel to be added on report, is this possible?
    Can we add Jpanel to Jasper report, if anybody has any thoughts and ideas please share with me?
    Thanks & regards,
    - Prashant

    Don't know exactly what you mean but this is how I add a JPanel to a JScrollPane.
    public class Scroll extends JFrame{
    JScrollPane jsp;
    JPanel panel;
    public Scroll(){
    jsp = new JScrollPane();
    panel = new JPanel();
    jsp.getViewPort().add(panel);
    getContentPane().add(jsp, BorderLayout.CENTER)
    }

  • How to I add text on top of image? I am using pages version 5.2.2

    I am working on an apple desk top OSX version 10.9.4. Since the new pages version 5.2.2 came out, I have been unable to add text on top of an image. Can anyone help me? Thanks ahead of time.

    Pages v5 is not as flexible as Pages ’09 v4.3. If you want text over a free-standing image in your document, then you will need to place it in a Text Box, Shape, or other custom container created with the Unite, Intersect, Subtract, or Exclude items in the Arrange panel. Simply selecting the image and then, in the Arrange tab, stating move with text; setting wrap to none, and clicking back/ward — does not help.
    You will need one of the containers from the second sentence positioned on top of your image. Once your text is input and styled, select the Text Box and the image, then from the Arrange tab, select group to maintain your text/image spatial relationship. If you need the image and its text container to adapt to other text in your document, you can enable the wrap functionality that best suits your document goals.
    This can get interesting, because you can independently define the selected Text Box content as a text placeholder, and the image as a media placeholder. Save it as a template. When you open a new document with this template, you can drag and drop a new image onto the old one, and it is automatically scaled and replaced without effecting the Text Box content. You can then double-click the Text Box content and change it.

  • Move "Add Document" to top

    Hello,
    I need to move "Add Document" to top of form library but cannot use SharePoint Designer nor any code. I'd like to use context editor but need to know exactly what script to use. Thanks in advance for any help.

    Hi,
    According to your post, my understanding is that you wanted to move the “Add Document” to top.
    You can add a content editor web part in the library, then use the following code snippet to achieve it.
    <style type="text/css">
    TABLE.s4-wpTopTable {
    POSITION: relative
    TD > DIV > TABLE {
    MARGIN-TOP: 25px
    TD.ms-addnew {
    POSITION: absolute; LEFT: 2px; TOP: 2px
    }</style>
    Thanks & Regards,
    Jason 
    Jason Guo
    TechNet Community Support

  • Add JPanel to a JFrame

    I have two classes. One is the main frame, and the other class is a panel. The constructor of the main frame looks like this:
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame("main");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel entryMgmt = new EntriesMgmt(dbConn);     
              frame.getContentPane().add(entryMgmt);
              frame.pack();
              frame.setVisible(true);The EntriesMgmt class extends JPanel. The constructor for it looks like this:
    public EntriesMgmt(SqlBackend.DbConn conn){
              this.conn = conn;
              JPanel pane = new JPanel();
              //Add radio buttons
              pane.add(initRadioBtns());
              //Add input area
              pane.add(initInputArea());
              //Add buttons
              pane.add(initButtons());
         }The problem is that only the main window appears and there is nothing in it. I tried creating another JFrame in the EntriesMgmt constructor but it would cause 2 windows to appear and i don't want to use internalFrame because what I'm actually trying to do is have a JTabbedPane in the main window and I would have external JPanel under each tab. But let's concentrate on why is it that my EntriesMgmt panel does not appera in the main window.

    What i did to fix this problem was the following. Since EntriesMgmt class extends JPanel I did not have to define another JPanel in the constructor but I could directly add components. Instead of :
    public EntriesMgmt(){
    JPanel pane = new JPanel();
              //Add radio buttons
              pane.add(initRadioBtns());
              //Add input area
              pane.add(initInputArea());
              //Add buttons
              pane.add(initButtons());I have:
    public EntriesMgmt(){
              //Add radio buttons
              add(initRadioBtns());
              //Add input area
              add(initInputArea());
              //Add buttons
              add(initButtons());And somehow it works. Anyways I would like to know if there was any other way to do it.

  • Simple question I think, add JPanel to JScrollPane

    I would imagine that for anyone with experience with Java this will be a simple problem. Why can't I add a JPanel to a JScrollPane using myScrollPane.Add(myPanel); ?? it seems to get hidden...
    This works correctly:
         //Create a panel
         JPanel panel = new JPanel(new FlowLayout());
         //Make it pink
         panel.setBackground(Color.pink);
         //Make it 400,400
         panel.setPreferredSize(new Dimension(400,400));
         //Create a Scrollpane
         JScrollPane scrollPane = new JScrollPane(panel);
         //Make it 300,300
         scrollPane.setPreferredSize(new Dimension(300,300));
         //Create a JFrame
         JFrame frame = new JFrame("Test Scrollpane");
         frame.setLayout(new FlowLayout());
         //Set close operation
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //Set its size
         frame.setSize(600,600);
         //Add Scrollpane to JFrame
         frame.add(scrollPane);
         //Show it
         frame.setVisible(true);
    This doesnt:
         //Create a panel
         JPanel panel = new JPanel(new FlowLayout());
         //Make it pink
         panel.setBackground(Color.pink);
         //Make it 400,400
         panel.setPreferredSize(new Dimension(400,400));
         //Create a Scrollpane
         JScrollPane scrollPane = new JScrollPane();
         scrollPane.add(panel);
         //Make it 300,300
         scrollPane.setPreferredSize(new Dimension(300,300));
         //Create a JFrame
         JFrame frame = new JFrame("Test Scrollpane");
         frame.setLayout(new FlowLayout());
         //Set close operation
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //Set its size
         frame.setSize(600,600);
         //Add Scrollpane to JFrame
         frame.add(scrollPane);
         //Show it
         frame.setVisible(true);

    rcfearn wrote:
    I would appreciate it you could read the sample code, I am asking the question as to why I have to do this? For structural reasons I don't want to have to add the JPanel during instatiation of the JScrollPane...Please read the [jscrollpane api.|http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html] To display something in a scroll pane you need to add it not to the scroll pane but to its viewport. If you add the component in the scroll pane's constructor, then it will be automatically added to the viewport. if you don't and add the component later, then you must go out of your way to be sure that it is added to the viewport with:
    JScrollPane myScrollPane = new JScrollPane();
    myScrollPane.getViewport().add(myComponent);

  • How to add JPanel,JFrame to JSP Page so that it does'nt popup

    i have added a JPanel jp1
    which is as follows
    <%JPanel jp1 = new JPanel();%>
    i am getting a error in the page in webbrowser
    javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=null,alignmentY=null,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
    also i have added a frame as follows
    <%adminlog adllogz = new adminlog();%>
    <%adllogz.setVisible(true);%>
    so these two lines of code make a poop up window of adminlog
    from a webbrowser
    what i want is that these two lines of code should not do
    a pop up but come inside a webbrowserPlease tell asap

    The problem is that you used position:absolute, my post talked about using position:fixed.
    Also your image does not need to be inside the adBox, just use adImage by itself with this CSS:
    #adImage{
    background-color: #FF0000;
    position:fixed;
    bottom:0px;
    right:0px;
    width:100px;
    height: 100px;
    will fix adImage to bottom right 0 px from the edge of window. If you want a little separation, just change
    bottom:0px;
    right:0px;
    to 5 or 10 px or so.
    No jQuery needed.
    Best wishes,
    Adninjastrator

  • Add compoenent on top of a Video

    Hello all i am trying to add a JButton on top of a movie
    but the button is not visible ,
    can you help me with that ?
    thank you
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import javax.media.Controller;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.Player;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    public class Test1 extends JPanel {
      private JComponent m_playerComp;
      private JPanel m_pnlDraw = new JPanel(new FlowLayout());
      private JLayeredPane layeredPane = new JLayeredPane();
      public Test1() {
        try {
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
          String url = "file://D:\\blender\\books\\EnvMapMirroring-XviD.avi";
          Player player = Manager.createPlayer(new MediaLocator(url));
          player.realize();
          while (player.getState() != Controller.Realized) {
            try {
              Thread.sleep(100);
            } catch (InterruptedException e) {}
          m_playerComp = (JComponent) player.getVisualComponent();
          m_pnlDraw.setOpaque(false);
          m_pnlDraw.add(new JButton("aaaaaaaaaaaa"));
          setBackground(Color.BLACK);
          layeredPane.add(m_playerComp, new Integer(1));
          layeredPane.add(m_pnlDraw, new Integer(10));
          setLayout(null);
          add(layeredPane);
          player.start();
        } catch (Exception e) {
          System.out.println("Error creating player");
          e.printStackTrace();
          return;
      public void doLayout(){
        super.doLayout();
        layeredPane.setBounds(0, 0, getSize().width, getSize().height);
        m_playerComp.setBounds(0, 0, getSize().width, getSize().height);
        m_pnlDraw.setBounds(0, 0, getSize().width, getSize().height);
      public static void main(String[] args){
        Test1 t = new Test1();
        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.setLayout(new BorderLayout());
        frame.setBounds(0, 0, 1024, 768);
        frame.add(t, BorderLayout.CENTER);
        frame.setVisible(true);
        frame.validate();
    }

    i thinking that implementing my on PlayerVisualCompoenent (this called render ?)
    but , what happens with different codec , a different VisualCompoenent will be called ?
    and how can i do that
    here is same code but using a glass pane
    i dont see my button
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import javax.media.Controller;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.Player;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    public class Test1 extends JPanel {
      private JComponent m_playerComp;
      public JPanel m_pnlDraw = new JPanel(new FlowLayout());
      private JLayeredPane layeredPane = new JLayeredPane();
      public Test1() {
        try {
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
    //      String url = "file://Y:\\Movies\\500 Days Of Summer (720p)\\500.Days.Of.Summer.720p.BluRay.x264-METiS.mkv";
          String url = "file://D:\\blender\\books\\EnvMapMirroring-XviD.avi";
          Player player = Manager.createPlayer(new MediaLocator(url));
          player.realize();
          while (player.getState() != Controller.Realized) {
            try {
              Thread.sleep(100);
            } catch (InterruptedException e) {}
          m_playerComp = (JComponent) player.getVisualComponent();
          m_pnlDraw.setOpaque(false);
          m_pnlDraw.add(new JButton("aaaaaaaaaaaa"));
          setBackground(Color.BLACK);
    //      layeredPane.add(m_playerComp, new Integer(1));
    //      layeredPane.add(m_pnlDraw, new Integer(10));
          setLayout(null);
    //      add(layeredPane);
          add(m_playerComp);
          player.start();
        } catch (Exception e) {
          System.out.println("Error creating player");
          e.printStackTrace();
          return;
      public void doLayout(){
        super.doLayout();
    //    layeredPane.setBounds(0, 0, getSize().width, getSize().height);
        m_playerComp.setBounds(0, 0, getSize().width, getSize().height);
    //    m_pnlDraw.setBounds(0, 0, getSize().width, getSize().height);
      public static void main(String[] args){
        Test1 t = new Test1();
        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.setLayout(new BorderLayout());
        frame.setBounds(0, 0, 1024, 768);
        frame.add(t, BorderLayout.CENTER);
        frame.setGlassPane(t.m_pnlDraw);
        t.m_pnlDraw.setVisible(true);
        frame.setVisible(true);
        frame.validate();
    }

  • How can I add callouts on top of anchored images in CS6?

    I am using InDesign CS6 on a MacBook. I have multiple anchored images in a long document. Some of the images require callouts, such as labels or arrows, which should display on top of the image and should always stay with the image as if these items were also anchored. Is there a way to layer images in InDesign so that they are all anchored?
    I tried grouping the callout objects with the anchored object, but you cannot select an anchored object and other objects at the same time. I know in Word you can create an image canvas and add multiple items to that, and they are all grouped together. Is there a way to do that in InDesign? Or would I have to anchor each callout along with its corresponding image?

    Peter, your advice was very helpful. However, the text boxes (callout labels) that are included in the grouped objects get distorted once the grouped objects are anchored. Each text box shows the red +. When I expand the text box to fit content, the text box expands vertically so that all of the text is below the originally anchored object.
    The other callouts (just lines) stay in place perfectly.  Any insight into why the text boxes don't behave the same way that the lines do?

  • Why does the sum of data in subfolders not add to the top folder?

    I am trying to remove folders in my primary drive of my MacPro so as to free-up space on the primary drive.  I have been using the Info button for each folder to see the total amount of data for that particular folder.  When I add up the data contained in each folder they sum to a substantially lower amount of Gigabytes that is shown by the info button for the top folder.  If you add the data shown in each of the top folders on the drive, the sum is considerable less than is shown for the drive in its info tab.  Why is there this difference in the sum of individual folders and the drive Gigabytes shown?  Is there data that is not apparent because hidden folders not shown in the Finder?

    Suppose you had folder with three one-byte files in it. GetInfo reports three bytes in the folder. But each file takes a whole number of allocation blocks on the drive, probably something like 12K total.
    Mac OS X also blurs exactly what is meant by a folder. For example, an Application is typically presented to you as one file, but if you look inside it, you would see that it may contain a hundred files in folders.
    Some Users have reported better luck using OmniDiskSweeper (run as admin) to show how much real disk space is taken up by various items -- the GetInfo byte counts can be hard to deal with.

  • Add Icon at top left of Application Install window

    How do I add an icon to the top left of the Application Install window? I have seen a few apps with this feature. I have already added the standard 16,32,48,128 icons with no issues.
    Is this a matter of having a verified code signed certificate?
    Thanks!

    OK, so the icon will automatically show up at the top left when packaged with a signed code cert.
    Is the icon grabbed from the standard set of icons? I'm assuming it's the 128 icon.
    I couldn't find any documentation on this, perhaps my search skills are lacking.
    Thanks again,

  • Why am I unable to add website to Top Sites?

    I have followed the directions for trying to add a web site into my top site area with no luck. I have room for two more top sites, but am having no luck at all. I can not figure out what I am doing wrong. Any help would be most appreciated.
    Thank you,
    Glenda Gonzalez

    HI Glenda...
    iMac Mac OS X (10.5.2) Your forum profile indicates you are running 10.5.2. If that is the case click your Apple Menu top left in your screen then click Software Updates. You should be running 10.5.8.
    Try Safari maintenance...
    From the Safari Menu Bar, click Safari / Empty Cache. When you are done with that...
    From the Safari Menu Bar, click Safari / Reset Safari. Select the top 5 buttons and click Reset.
    Go here for trouble shooting 3rd party plugins or input managers which might be causing the problem.
    Safari: Add-ons may cause Safari to unexpectedly quit or have performance issues
    And make sure Safari is not running in Rosetta. Right or control click the Safari icon in your Applications folder then click Get Info. In the Get Info window click the black disclosure triangle so it faces down. *Where you see Open using Rosetta... make sure that is NOT selected.*
    

Web pages now include a small icon or 'favicon' which is visible in the address bar and next to bookmarks. These icons take up disk space and slow Safari down. It is possible to erase the icons from your computer and start fresh. *To delete Safari's icon cache using the Finder, open your user folder, navigate to ~/Library/Safari/ and move this file "webpageIcons.db to the Trash.*
    Carolyn

  • Can you place an image in a div tag and then add type over top of it?

    I told someone in class lastweek that I wanted to be able to
    place type over an image. They said you can just add the image into
    the div tag as a background image, which will allow you to then
    type over it if you like. How is this done? I have tried and
    failed. I have an image that is 200x590 going down the left side of
    my page. I want to run type over it, and keep the image consistent
    on every page, but change the header and type. I've seen this in
    several sites. How do you do this with the div tag box model method
    of building a page. Can I insert an image into the div and then run
    type over it. What does the code look like?

    Here's an example of using a css and a background image to a
    table cell...
    sample principle for a div
    #div {styles go here{
    http://tinyurl.com/yqeptp
    You may also want to go through the beginner css tutorials at
    the Adobe
    site:
    http://www.adobe.com/devnet/dreamweaver/css.html
    (pay attention to the ones
    by Adrian), beginner moving onto to creating full css
    layouts.
    Hope this helps :-)
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Customisation Service Available ~
    http://www.csstemplates.com.au
    Forum Posting Guidelines:
    http://www.adobe.com/support/forums/guidelines.html
    >I told someone in class lastweek that I wanted to be able
    to place type
    >over an
    > image. They said you can just add the image into the div
    tag as a
    > background
    > image, which will allow you to then type over it if you
    like. How is this
    > done?
    > I have tried and failed. I have an image that is 200x590
    going down the
    > left
    > side of my page. I want to run type over it, and keep
    the image consistent
    > on
    > every page, but change the header and type. I've seen
    this in several
    > sites.
    > How do you do this with the div tag box model method of
    building a page.
    > Can I
    > insert an image into the div and then run type over it.
    What does the code
    > look
    > like?
    >

  • How do you add a desk top icon to your desk top

    You use to be able to right click on the mouse and get a box with several options, which included, one that ask if you wanted to place icon on your desk top, for the page you had up. I can no longer, using, Thunderbird find a tab for adding icons to your desk top. Is there a way to still do it or not. Please let me know. Thank you, Robert

    http://windows.microsoft.com/en-us/windows-8/create-desktop-shortcuts-icons

Maybe you are looking for

  • How to manage more than one iPOD on just one PC.

    How do I manage my fifth gen. iVideo and my Nano files conveniently on one PC? It is easy to lose songs and get disoriented with how to keep from losing songs going from one to another?

  • GL account creation issue - reg

    hi guys, i created a GL ACCOUNT "500001". step 1: i created the PO and assigned the mentioned GL account ....it's working. step 2 : I did the goods receipt it's working. step 3 : When i try to to the invoice (MIRO)  by using the created PO ....(which

  • Table query on order and further goods movement

    Hi We have notification and Purchase requisition data in a Z table . For each notification we know equipment and for each equipment we know its standing order . Now from standing order we would like to know linked PR , PO , SES values . The purpose o

  • Automatically Delete Troubled Files

    You know those stupid files that have those stupid exclamation marks next to them is there a way to simply delete those without having to click multiple times on the song and manually do it?

  • How to use PKCS related classes?

    Hi, I am happening to deal with PKCS7. The client will send me (the server) a PKCS7 envelope and I need to decrypt and/or get data like certificate, etc from the PKCS7 envelope. Are the required/related classes not part of Java API? We use 1.4.2_06.