Components disappearing

hi...I got some components in an applet, for example...
Button btn = new Button("Click");
List list = new List(5,false);
now in my init method, I don't want some flowLayout to TRY to control the location of my components,
so I'm setting the flowlayout at null...
but as soon as I do this, the components disappear...
if I use a flowlayout like
setLayout(new FlowLayout(FlowLayout.CENTER));it works, but my composants arent placed right...
what's wrong ? isn't there a way for me to manually set the x/y of my components without them disappearing
setFlowLayout(null)
add(btn);
btn.move(BTN_X,BTN_Y);
add(list);
list.move(LIST_X,LIST_Y);

Layout managers are easy to learn to work with and some are very flexible in allowing you to place components just where you want them. They work well in resizing and in scrollpanes.
If you try to do this on your own you may soon come to appreciate the layout managers.
To get started, use setBounds to specify the location and size of your components in their container. To move them you can do:
    int dx = position change along x-axis;
    int dy = pixels;
    Rectangle r = myComponent.getBounds();
    myComponent.setBounds(r.x + dx, r.y + dy, r.width, r.height);
    parentComponent.revalidate();  -or- parentContainer.validate();
    parentComponent.repaint();Becoming proficient in layouts requires practice and patience.

Similar Messages

  • SetBounds(0,0,-1,-1) make components disappear

    Hi all,
    I work with Sun One Studio 4, I designed a quite sophisticated form layout (only using Border and BoxLayout though) with a bgImage. It worked ok. Then I rewrote button texts. Almost all of the components disappeared (all from one of the main panels). I compared the working version with this new one (even the layout managers are the same), and found that there are 2 lines that differ, those ones that dimension the panels of my JLayeredPane. In the working:
    jPanel1.setBounds(0, 0, 810, 610);
    jPanel2.setBounds(0, 0, 324, 134);
    in the erroneous:
    imagenFondoPanel.setBounds(0, 0, -1, -1);
    menuNavegadorPanel.setBounds(0, 0, -1, -1);
    My questions:
    1. What does the this latter semantic (the -1 s in the setBound) mean?
    2. How can this ruin my working version?
    3. Can absolute positioning appear only using Layout Managers?
    Thank you for your answers,
    Balint Erdi

    the message signature is as follows:
    public void setBounds(int x,
    int y,
    int width,
    int height)
    the first two parameters specify the location of the component
    and the later two components specify the Width and height respectivly.
    so setting them to -1, -1 makes no sense, because obviouslly your
    component disappears

  • Components disappeared after adding the image in.....

    Hello everyone,
    I add a image in my home page that is in swing .As soon as I add that image the components in another page disappeared.(Componenets like textField ,Label).But when I click on that page, those pages appears. I want to appear all those pages at the first time as they are working before adding the image .
    Please tell me the solution on my ID or provide the solution over here.
    Thanks
    Vivek Kumar Gupta

    wht do u mean by pages.. ??
    and I should suggest you to use..
    validate();
    after adding images..

  • Components disappear after having moved them

    Hi again,
    I've created a JFrame which looks like this:
    This is all fine until you hit the big O (maximize). Here is the code I use for the button:
    if (source == maximize) {
                if (this.getBounds().width != (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() & this.getBounds().height != (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
                    this.setBounds(0, 0, (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight());
                } else {
                    this.setBounds(Integer.parseInt(p.getProperty("screen.x_pos")), Integer.parseInt(p.getProperty("screen.y_pos")), Integer.parseInt(p.getProperty("screen.x_bound")), Integer.parseInt(p.getProperty("screen.y_bound")));
                maximize.setIcon(over_maximize);
                updateScreen();
            }And here is the code for updateScreen:
    public void updateScreen() {
            // Reposition the components
            close.setBounds(this.getBounds().width - 23, 0,  23, 26);
            maximize.setBounds(this.getBounds().width - 47, 0,  24, 26);
            minimize.setBounds(this.getBounds().width - 69, 0,  22, 26);
        }When i hit the maximize button then, it properly resized, and the components are moved. I know they should be visible, but somehow they disappear. Here is a screenshot of what it looks like (i moved the X button to the edge to show you what i'm talking about.
    What am i doing wrong?
    MANY thanks in advance!

    Also I would limit the legth of each line of code. Its hard to read your code when you need to do horizontal scrolling all the time. One way to shorten you code is to do something like the following:
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screen = toolkit.getScreenSize();
    Now you can just use: screen.width and screen.height.

  • Components disappears, when Jbutton is pressed..

    Hi all,
    I have a simple application running with JFrame. On JFrame I have a JButton, and on clicking JButton.... I initialize a new object, whose one method is called after that which sends mails... now untill the mail sending method has returned, the components on JFrame disappears. Only JLabel are visible on JFrame. All JtextFields and Jbutton and JprogressBar are gone. Can anybody give me an idea that how to prevent this.
    Thanks for ur time..
    --Praveen                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thanx for ur valuable suggestions.... Lemme try it with invoking new Thread to send Mails.. Meanwhile please send more suggestions...
    --Praveen                                                                                                                                                                                                                                                                                               

  • 9iAS System Components Disappeared

    Where did all my components go?
    In a development environment, we are running an instance of 9iAS v9.0.3 on Red Hat Linux v2.1. The instance is part of a farm on another server where the infrastructure is on 9iAS v9.0.2.
    We had one web application deployed (struts) that uses a Resource Adapter that makes connections to a legacy DB via a pool. The application began hanging during db connections. In trying to restart the OC4J component or the entire instance I kept getting a timeout error. I decided to reboot the machine.
    Reboot was successful and emctl starts successfully however when I look at it via the EM, there are no components listed. And nothing seems to loaded or working. Very wierd! Trying via dcmctl to start things doesn't seem to help but that may just be my lack of experience.
    Anybody have any suggestions?

    Can any body please reply to this?
    Thanks,
    Ronny

  • Subclassing JComponent. Components, disappear

    Hi
    I hope you can help me with this annoying problem. I have coped with it for ours but couldn't get it to work.
    I subclassed a JComponent and have overridden its paintComponent method.
    When I add the Component to my Jpane, it's visible, but If I do Jpane.validate() (which I'm supposed to do, according to the doc) my custom component moves to the upper left (6,6) and is one pixel in height.
    I was able to keep its size with component.setPreferredSize instead of component.setSize.
    But what can I about the moving of my component?
    thank you for your help

    Your component is just a regular component so it will be positioned in your frame based on the LayoutManager you are using. Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

  • Swing Components and Fullscreen Exclusive

    Hi, I am trying to write a program that can switch between full screen and windowed mode seamlessly, while still being able to use standard swing components. I have never worked with the full screen exclusive mode before and am having trouble getting the components to repaint properly.
    The following code works fine in the windowed and undecorated modes, however when I switch to fullscreen exclusive mode all components disappear and only repaint upon mouseover or other interaction. Calls to repaint do not make any difference.
    import java.awt.Dimension;
    import java.awt.DisplayMode;
    import java.awt.FlowLayout;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    public class FullscreenTests {
         private static boolean hwlast = false;
         private static GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
         public static void main(String[] args) {
              final JFrame fMain = new JFrame("Title");
              fMain.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              fMain.getRootPane().setLayout(new FlowLayout());
              JButton win = new JButton("Windowed");
              win.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setWindowed(fMain);
              fMain.getRootPane().add(win);
              JButton ful = new JButton("Fullscreen");
              ful.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setFullscreen(fMain);
              fMain.getRootPane().add(ful);
              JButton hw = new JButton("HW Fullscreen");
              hw.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setHWFullscreen(fMain);
              fMain.getRootPane().add(hw);
              setWindowed(fMain);
         public static void setWindowed(JFrame f) {
              if (hwlast == true) {
                   dev.setFullScreenWindow(null);
                   hwlast = false;
              f.dispose();
              f.setIgnoreRepaint(false);
              f.setUndecorated(false);
              Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
              f.setSize(new Dimension(808,634));
              f.setMinimumSize(new Dimension(808,634));
              f.setLocation((d.width-f.getWidth())/2, (d.height-f.getHeight())/2);
              f.setVisible(true);
         public static void setHWFullscreen(JFrame f) {
              hwlast = true;
              f.dispose();
              f.setUndecorated(true);
              f.setIgnoreRepaint(true);
              f.setVisible(true);
              dev.setFullScreenWindow(f);
              dev.setDisplayMode(new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN));
         public static void setFullscreen(JFrame f) {
              if (hwlast == true) {
                   dev.setFullScreenWindow(null);
                   hwlast = false;
              f.dispose();
              f.setIgnoreRepaint(false);
              f.setUndecorated(true);
              f.setSize(Toolkit.getDefaultToolkit().getScreenSize());
              f.setLocation(0,0);
              f.setVisible(true);
    }On the same note, if there are better ways of doing this I would be glad to know. This is just a quick test so I haven't done any checks etc when switching to fullscreen exclusive.

       public static void setHWFullscreen (JFrame f) {
          hwlast = true;
          f.dispose ();
          f.setUndecorated (true);
          f.setIgnoreRepaint (true);
          // add this
          Graphics g = f.getGraphics ();
          f.paintAll (g);
          f.setVisible (true);
          dev.setFullScreenWindow (f);
          dev.setDisplayMode (new DisplayMode (800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN));
       }db

  • Painting over components

    Hi,
    I have the following panel which displays a series of labels, however when i try and draw a string onto the panel, all of the components disappear when the string is drawn, can someone please help me.
    Thanks
    Cath
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class CurrentPlayersPane extends JPanel
         public CurrentPlayersPane()
              setLayout(null);
              red = new ImageIcon("images/red.gif");
              yellow = new ImageIcon("images/yellow.gif");
              green = new ImageIcon("images/green.gif");
              blue = new ImageIcon("images/blue.gif");
              cyan = new ImageIcon("images/cyan.gif");
              magenta = new ImageIcon("images/magenta.gif");
              red_l = new JLabel(red); red_l.setBounds(RIGHT, 10, 14, 14); add(red_l);
              yellow_l = new JLabel(yellow); yellow_l.setBounds(RIGHT, 27, 14, 14); add(yellow_l);
              green_l = new JLabel(green); green_l.setBounds(RIGHT, 44, 14, 14); add(green_l);
              blue_l = new JLabel(blue); blue_l.setBounds(RIGHT, 61, 14, 14); add(blue_l);
              cyan_l = new JLabel(cyan); cyan_l.setBounds(RIGHT, 78, 14, 14); add(cyan_l);
              magenta_l = new JLabel(magenta); magenta_l.setBounds(RIGHT, 95, 14, 14); add(magenta_l);
              player1 = new JLabel(); player1.setBounds(RIGHT+20, 10, 100, 14); add(player1);
              player2 = new JLabel(); player2.setBounds(RIGHT+20, 27, 100, 14); add(player2);
              player3 = new JLabel(); player3.setBounds(RIGHT+20, 44, 100, 14); add(player3);
              player4 = new JLabel(); player4.setBounds(RIGHT+20, 61, 100, 14); add(player4);
              player5 = new JLabel(); player5.setBounds(RIGHT+20, 78, 100, 14); add(player5);
              player6 = new JLabel(); player6.setBounds(RIGHT+20, 95, 100, 14); add(player6);
              arrow = new ImageIcon("images/arrow.gif");
              arrow_l = new JLabel(arrow); add(arrow_l);
         public void paint(Graphics g) {
              g.drawString("Hello World", 75, 50);
         // displayName() - Display the name of a player on the game board
         private void displayName(String name, int playerNo) {
              switch(playerNo)
                   case 1:
                        player1.setText(name);
                        break;
                   case 2:
                        player2.setText(name);
                        break;
                   case 3:
                        player3.setText(name);
                        break;
                   case 4:
                        player4.setText(name);
                        break;
                   case 5:
                        player5.setText(name);
                        break;
                   case 6:
                        player6.setText(name);
                        break;
         // moveArrow() - Move the arrow to point to the current player
         public void moveArrow(int playerNo) {
              arrow_l.setBounds(10, ARROWPOS[playerNo - 1], 29, 15);
         private Icon red, yellow, green, blue, cyan, magenta;
         private JLabel red_l, yellow_l, green_l, blue_l, cyan_l, magenta_l;
         private JLabel player1, player2, player3, player4, player5, player6;
         private ImageIcon arrow;
         private JLabel arrow_l;
         private final static int RIGHT = 45;
         private final static int[] ARROWPOS = {10, 27, 44, 61, 78, 95};
    }

    sorry, one more question, i need a panel which needs to shows some components (e.g. JSlider and labels) only at specific times. So there will be a blank panel most of the time but occasionally i will need to show these components, how can i achieve this?
    Many thanks
    Cath

  • Button Components don't show

    I have a problem with the button components disappearing when
    I publish the flash file through Dreamweaver on the internet.
    The buttons are generated with actionscript 3.0 and are in a
    movie clip, with moves with the mouse. I use addChild to add each
    button and three sub-buttons in the movie clip.
    When I export the swf file to Dreamweaver and view it in the
    browser, the graphics on the page appear, but the buttons are
    absent.
    When I decompiled the swf file, they show again!
    What could this be? Any help is appreciated.

    Yes, I have Flash 9 on Firefox and IE.
    The Decompiler is Trillix.
    I've isolated the problem to the XML file that is loaded to
    the flash. When the button is labeled with a text string and added
    with addChild, it shows. But when I load the XML file with the data
    and add with the line below (g[n] is the name of the field, n is
    index) it only shows in the preview.
    var myLoader:URLLoader = new URLLoader();
    var xml:XML;
    myLoader.addEventListener(Event.COMPLETE, onComplete);
    myLoader.load(new URLRequest("
    my php generated xml file
    function onComplete(e:Event):void{
    xml = new XML(e.target.data);
    myButton.label = "main";
    Works
    myButton.label = xml..g[n].text();
    Works in flash, but not browser

  • Problem with publishing in cs5

    Hi, we seem to be expiriencing the following issues with cs5 trial version.
    The problem:
    After making changes to a perfectly working fla it won't publish correctly,
    meaning:
    1. When previewing all the components jump (as usually happens when there is
    a compile error) but no error is displayed in the log.
    In this case when used with the whole project, the project doesn't load,
    even though the corrupted fla is not the first loaded (non of the fla loads
    besides the preloader).
    2. When previewing and running with the whole project the labels on the
    button components disappear, but only the ones that are dynamically changed
    by an external as file.
    *there are other similar bugs as well like unable to enter the table in the
    game etc.
    The changes I make before it happens:
    - changing the size of a shape inside a movie clip.
    - changing the size of a movie clip.
    - changing anything in an already existing code (like changing the size of a
    font).
    - adding new basic code anywhere (like trace code).
    - changing button skins.
    Basically, any change I make corrupts the file but not consistently,
    meaning,
    I can make the same change twice and the file will break only one of the
    times, or, I can make several changes until it breaks.
    It also happens on every computer but also, not consistently, I can work for
    a while, making the same change, deleting, making the change again etc, only
    on the fifth or sixth time the file will break. On a different computer it
    can take only two or three times.
    The corrupted file start working again after I change the name of the folder
    containing my project or move all the files to a different folder anywhere
    on my computer. After a short while the file crushes again.
    p.s, i used the latest cs5 updates and that did not solve the problem.
    thanks in advance.
    David.

    Seems you have encountered a weird problem. I have been using CS 5 for quite sometime now without any such issues.
    Would it be possible for you to share an example fla that is causing the problem.
    It would be great if you could provide a copy of the fla that gets published ( before making changes)
    and a copy of the fla that is broken ( after making changes)
    If it is possible for you to provide the fla then probaby I could help you out in finding the issue.

  • Full-Screen bug with Safari

    I hope this is already a known issue.
    I use Safari on Mac OS X. In my flex application, I have
    problem with full-screen mode. When I get back to normal mode from
    full-screen mode, and then resize or maximize safari window, the
    screen displays abnormally. Most of components disappears, and
    sometimes all of them. The same problem occurs with other video
    players, including the one in youtube. I haven't tested it with
    other browsers yet. I hope this problem is fixed in future release.
    Thanks,

    Chaos,
    Can you please file a bug in the bugbase (
    http://bugs.adobe.com/flex)
    and somebody can have a look at it. Also, be sure to mention which
    version of OS X, Safari, and the Flash Player you're using. And if
    you have any source code showing the problem, that definitely
    helps.
    I did a quick test and i was unable to repro the issue using
    the latest Flex 3 SDK on XP/IE7, XP/Firefox, OSX/Safari and
    OSX/Firefox (WIN 9,0,60,163 and MAC 9,0,60,161).
    Peter

  • How to re-install Photoshop CS4 demo?

    I am interested in upgrading from CS3 extended, so I downloaded the demo of CS4. Yesterday I succeeded to install, worked OK, but because I had some video driver problems, not related to Photoshop, I had to roll back my system to several days ago (restore). After that, I tried to install again, many times, no go! I used also the instructions from: http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403891
    directed from the Adobe Support Advisor. Still no success!
    I am afraid that if the problem persists, I might not be able to install the upgrade later!
    My system is a Dell Studio XPS 435mt (PROCESSOR iNTEL cORE I7-940, WINDOWS 64 BIT)
    Your help would be very appreciated!
    Thanks
    Max

    mtz222 wrote:
    Thanks to replies... so in short: if I buy, there should not be such installation problems, right?
    Yes. What has happened to you is simply that the trial has flagged your drive and when you rollback, the checksum/ fingerprint changes, which the licensing system considers an attempt of tampering. Everything will be fine once you buy the product and enter aa valid serial. Should your rollback have some other sideeffects on your install like certain components disappearing, use the CS4 clen utility from teh support pages before attempting any re-install for the retail version.
    Mylenium

  • Component addition in Production order.

    Iam doing Sales order Mrp. After that planned order is converted into production order.
    Bom components appear in pegged requirements.
    In production order change mode I delete some components and refresh MD04. Components disappear from pegged requirement. It is ok
    Now In production order change mode I add some components and refresh MD04. Components does not appear in pegged requirement.
    I do MRP again but Components does not appear in pegged requirement.
    How to get components in Pegged requirement list??

    Hi,
    Why requirement for new component does not get added when MD50 is carriied out??
    While running MRP using T-code MD50, The system will explode BOM and it will do the net reqmt calculations. Since the newly added component is not part of the BOM, that is the reason it is not considered.
    After doing Plant level MRP requirement for that component gets generated but it does not appear in pegged requirement of header material??
    When you add the component in the production order, it will create the reservation. In the next MRP run only this reservation will be considered and it will plan.
    Regards,
    V. Suresh

  • Help request - JFrame re-use problem - Painting issues

    Hello,
    I'll give a short background on the problem:
    The general purpose of my program is to display a series/sequence of screens in a spesific order. I have constructed an object (JFrame) for each of those screens. In the beginning I create a Vector containing information about every screen in the sequence and when the time comes for that screen to appear I use that information to create the screen.
    In my first design I created a new object for each screen (I have 6 basic types of screens but they often appear with different data - graphs and tables and such) while after I was done with a screen I released the reference to it. For some reason the memory requirement of that design were immense and kept increasing with each new screen.
    To remedy that I switched to a re-usage (recycling sort of say) design. I created a cache of screens, 1-2 of each type depending on whether two screens of the same type may appear one after the other. When a screen appears for the first time, I use the constructor to initialize it and save it in the cache but for future usage I "re-initialize" the old screen with the new data. Only after I finished re-initializng the screen I set it's visibility to true.
    Coming to the problem at last: as I understand seeing as the update of the frame's contents finishes before the screen is displayed it should already be displayed in it's updated form, BUT instead it appears with the old data for a split second and then repaints on-the-fly. You can actually see some components disappearing/appearing. This is a pretty nasty visual effect that I cant figure out how to overcome but worst of all I dont understand WHY it happens...
    **Edit:* Please read P.S. 3, just to show, this is not because I have a slow computer (it's quite new and has plenty of RAM) and I gave the heap plenty of space so it's not an issue of increasing it with each allocation
    I kindly ask for any help/advice on why the problem happens and how to fix it.
    Thank you in advance.
    P.S. I tried to pipeline the updates, say screen 1 is currently displayed so when the button to move on to screen 2 is pressed, screen 3 is re/initialized and so on. I used a seperate thread but it was synchronized with the displaying method so it should've been just like sequential updates but only less time consuming. When that didn't work I did the sequential update (which I described above) which didn't work either.
    P.S. 2. I gave the background in case it might help and to show that an advice of the sort "don't re-use and just create a new object" is out of the question =\
    P.S. 3 Something very odd I nearly forgot to mention: I work in Eclipse, and when I run it there I don't encounter this problem, it runs smoothly and there are no such painting problems but when I run it externally from the command line, that's where these problems occur and that is how the program will eventually be used. I don't understand why there is a difference at all, after all the JVM is one and the same in both cases, no? =\
    Edited by: Puchino on Dec 24, 2007 10:06 PM
    Edited by: Puchino on Dec 24, 2007 10:12 PM

    First off, It SEEMS I solved the problem by calling dispose() on the frame once I finished using it, then comes the manual updating and when I set it's visibility to true it no longer does any of weird painting problems it used to. Question is why does it work? I assumeit has something to do with the fact dispose releases the visual resources but could someone please provide a slightly more in-depth explanation?
    Second, at the moment my code doesn't have any calls to validate or invalidate or repaint (and I can't call revalidate) because JFrame doesn't inherit from JComponent. So I'd like to know please, which of these methods should I call in case I manually update the frame's contents?
    Third, I'll attempt to recreate a short sample code later on today (must be off now).
    P.S. Thanks for the replies!

Maybe you are looking for

  • After upgrade to 10.8 does not import movies

    Hi, I use Final Cut Pro V 7, MPEG Streamclip and VLC to import video files. I have very recently upgraded my OSX to 10.8.4 and although it plays my movie clips  (downloaded from my SD card to hard drive) in Quicktime and VLC and it will not play afte

  • Can You Set-up a Sub mail Address Folder?

    I'm switching from Microsoft Outlook Mail to the Apple address and I wondering if there is a way to set-up a sub address folders like I can do in Outlook. See example? Business - Services for My Business - My customers - Personnel services - Etc. Any

  • My Nokia C3 is not supporting softwares

    I have tried so many ways to download softwares, but to my efforts are all fruitless. When i go to other sites to download and install softwares, the place to download the software will not even be active and when i download from ovi store it is not

  • Gos attachment knowlenge provider:  transfer error ?

    hi friends ı wrote this code but ı take this error 'Knowlenge provider : transfer error'. please help me ? thanks. DATA: o_document_set TYPE REF TO cl_bds_document_set,   wa_signature LIKE bapisignat,   i_signature LIKE bapisignat OCCURS 1,   wa_file

  • Load external images

    Im wanting to make a photo gallery that I can update easy, I thought if I could have a movieclip load external images for my thumbnails it would be nice but Im not sure how to set it up. I would make a file for my images and then another for my thumb