How do you define the width of a JPanel?

How do you define the width of a JPanel?

it may not be perfect but this is what i have tried:
import javax.swing.*;
import java.awt.event.*;
public class myPane extends JFrame {
     public myPane() {
          super("myPane");
          setDefaultCloseOperation.(JFrame.EXIT_ON_CLOSE);
          JButton myButt = new JButton("press");
          JPanel pane = new JPanel();
          pane.add(myButt);
          setContentPane(pane);
     public static void main(String args[]) {
          myPane p1 = new myPane();
          p1.setBounds(20, 20, 600, 400);
          p1.setVisible(true);
}

Similar Messages

  • How do i get the width of a JPanel

    Hey
    Im trying to get the width of my JPanel with this code, but it just prints 0, what am i doing wrong?
    public class GamePanel extends JPanel implements Runnable {
         private static final int PWIDTH = 500;   // size of panel
         private static final int PHEIGHT = 400;
         private static final int NO_DELAYS_PER_YIELD = 16;     
         private static int MAX_FRAME_SKIPS = 5;
         private MovingGame frame;
         private Thread animator;
         private volatile boolean running = false;   // used to stop the animation thread
         private long gameStartTime;   // when the game started
         private BallSprite ball;
         //      off-screen rendering
         private Graphics dbg;
         private Image dbImage = null;
         //      holds the background image
         private BufferedImage bgImage = null;
         public GamePanel(MovingGame frame){     
              this.frame = frame;
              setDoubleBuffered(true);
              setBackground(Color.blue);
              setPreferredSize( new Dimension(PWIDTH, PHEIGHT));
              setFocusable(true);
              requestFocus();
              addKeyListener( new KeyAdapter() {
                   public void keyPressed(KeyEvent e)
                       { processKey(e);  }
              ball = new BallSprite(40, 40, this);
              System.out.println("Width: " + getWidth());    <------- this prints 0
         }

    veldhanas wrote:
    Hi,
    Use
    setSize(PWIDTH, PHEIGHT); instead of
    setPreferredSize( new Dimension(PWIDTH, PHEIGHT));ThanksWrong Wrong Wrong Wrong
    .setSize() sets the size of the component at that instant in time and has no effect on anything the layout managers do with the component. .setPreferredSize() sets the size the layout manager will look at (assuming it cares about what size you want the component at).

  • How do you adjust the width of the panel bin?

    I just got Elements 9.  In the earlier versions you could drag the line that separates the panel bin from the rest of the workspace to adjust its width.  Also, you could double click the center of this same separator line to minimize the panel bin.  Once it was minimized you could bring the bin back by double clicking the line on the far right edge of the screen.  That does't seem to work anymore in Elements 9.  I see where you can minimize the panel bin by unchecking it under "Window" in the menu bar, but double clicking was a lot faster and I haven't been able to figure out how to adjust the width.  Any help would be appreciated.  Thanks.

    Thanks for the response.  Too bad you can longer adjust the width.  I used that option a lot on my earlier versions.   Oh well, I am sure there are other improvments that more than make up for it.  Thanks again.

  • How do you change the image in a JPanel?

    Hey! (firstly, i need to use image on a JPanel, label&icon not an option).
    I've made my JPanel class
        public class DrawingPanel extends JPanel {
            Image img;
            DrawingPanel() {
                Image img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
            public void paintComponent (Graphics g) {
                super.paintComponent (g);
                // Use the image width & height to find the starting point
                int imgX = getSize ().width/2 - img.getWidth (this);
                int imgY = getSize ().height/2 - img.getHeight (this);
                //Draw image centered in the middle of the panel   
                g.drawImage (img, 0, 0, this);
            } // paintComponent
        } // DrawingPanelAnd I've made my instance of it and added it to the Frame:
        DrawingPanel imagePanel = new DrawingPanel();Now, I need to change the image on the JPanel according to the user's input. I have the string of the location of the new image. How do I update the JPanel to display this new image? Any help greatly appreciated!!

    Well... You could just add a method in your class which sets the image according to the new image name you provided. Something like this:
        public class DrawingPanel extends JPanel {
            Image img;
            DrawingPanel() {
                img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
            public void setImage(String imageName) {
                    img = Toolkit.getDefaultToolkit().getImage(imageName); //Loading the desired image
            public void paintComponent (Graphics g) {
                super.paintComponent (g);
                // Use the image width & height to find the starting point
                int imgX = getSize ().width/2 - img.getWidth (this);
                int imgY = getSize ().height/2 - img.getHeight (this);
                //Draw image centered in the middle of the panel   
                g.drawImage (img, 0, 0, this);
            } // paintComponent
        } // DrawingPanel

  • How can i define the width of report column in report region ?

    Hi,
    I have report region and i want to have a static width for each column ( not based on column name of column data ), how can i do it ?
    Thanks in advance ,
    Yoel

    Can you provide more details pls? I am also trying to change widht of report columns and I do not see anywhere in reports atrributes where it allows me to do that...Thanks so much!

  • How do you define the categories in All My Files?

    right now All My Files seems to have a predefined set of categories it lists. But I can't seem to find a way to take out categories that I don't need. How can i take them out of the search?

    If I understand your question, I believe this is what you are seeking:
    Note the selection on the menu bar.
    Also use COMMAND+J and select 'Calculate all sizes'.
    Ciao.

  • Using the APIs - how do you define the application?

    After using lite for a long while, i am finally getting around to evaluating ways to override/improve the compose process as this is becoming a real problem for us.
    as i see it there are 3 main options
    1) call out pl/sql package - got this working, but does not directly affect the compose
    2) mycompose - despite not being a java person, got this working, and this does reduce the compose impact (the inconsistencies in the PK name mapping threw me a bit, but thats oracle lite for you)
    3) queue based publication items to bypass the MGP process entirely. following the examples (and a lot of make it up as you go along) i managed created a publication via the consolidator APIs, added the publication items, added and instantiated a user, synced and all seems to be working (at least in outline), but the publication i have created is not attached to any application so i cannot maintain the users via the applications tab as normal. found the resourcemanager API to create the application (i think), but cannot find any way to associate my publication with it
    Am i missing something? or can i just not manage to find the correct API?

    Firstly i will point out that the underlying source of our 'issues' is poor main system database design (politics and in place before i arrived), and this has pushed us down a couple of possibly non standard routes
    1) quite a number of publication items based on complex updatable views (too much normalisation on the server side, and the performance overheads for high numbers of table joins on the PDA clients we use have forced this)
    2) complex data subsetting (using relationships disconnected from much of the actual data)
    the issues we have are
    a) poor performance in the MGP compose on a few of the view based objects (they have been extensively tuned, conspref steeing as good as they can be, but the execution plans generated by the standard compose process wrapping is poor)
    b) updates to view 'content' only happen by default if the base table of the view is updated (this is where it gets the version from)
    c) increasing MGP compose time (for roughly the same number of users this have gone from an average of about 1-2 hours to 8-12 over the past 12 months - this is probably more related to server application design issues, increasing data volumes and possibly conflicts with streams being used for other applications)
    d) performance overhead in terms of resource (CPU, IO) usage when compose is running
    e) locking conflicts between the main server system and the MGP process (either the process log phase failing in mobile due to transaction locks on all_sid_logged_tables preventing the compose from starting, or server transaction being blocked for a few minutes due to the exclusive locks needed for the process logs phase)
    Due to the above i decided to do a proof of concept type study on the 3 alternative approaches for controlling the MGP process (before/after callouts, mycompose and queue based publication items).
    results so far
    - before/after callouts do not affect the actual compose processing, so not much use (but we are looking at these for intercepting some standard issues from the client applications and correcting the data before it hits the error queues)
    - mycompose - despite minimal java knowledge (and the undocumented issues like the poor execution of moving data from the cpd tables to the cmp tables), i have been able to demonstrate 60-90 reduction in compose time for the most problematical objects - sorts out issues a-c, helps with d, but does not do much about e
    - queuebased publication items - seriously cumbersome at the moment (may be able to make it more generic), but PL/SQL that i am more comfortable with (except for the actual publish) - still working on this, but so far at the cost of an increase in average client sync time from about 1-2 minutes to about 5-8, i have managed to get a working application (30 complete refresh items plus 44 queue based) that does not require the MGP process to be running or enabled, and needs no CVR/CLG/all_sid_logged_tables logging, so looks to achieve all of the objectives plus a performance improvement overall on the main server system
    no final decisions yet, the queue based approach looks best, but would be problematical in doing the switchover without losing any client data, mycompose is easy to overlay over the existing application, but does not fully meet all objectives

  • How do you change the click box properties (line colour and width) in Captivate 7.0?

    How do you change the click box properties (line colour and width) in Captivate 7.0?

    Yes certainly, we can do that, insert a smart shape and use it as a button, then go to the properties pane, change the Alpha to 0, that will make it transparent, and add the stroke color as red and increase the width.
    In case of a button, you have to select button type as transparent and do the same.
    Thanks.

  • How do you change the column widths in a master-detail input form?

    I have changed several columns to af:inputText so that the field contents can be modified, but this defaults the column width to a huge size, way past the size of the actual data field itself. Modifying the width attribute is ignored and dragging the column dividers is also ignored.
    How do I reduce the widths of these columns?
    Thanks

    Hi,
    maybe this blog entry "Referencing Maximum Length of an Attribute in an EL Expression" by Steve Muench helps
    http://radio.weblogs.com/0118231/2007/06/04.html#a839
    Frank

  • How do you find the number of lines in a file?

    I need to count how many lines there are in a file, I am using a BufferedReader to read in the data, but how can I find the number of lines?
    Thanks

    That depends. How do you define a line? Is it a specific number of
    characters, a String that's terminated by a newline character or some
    combination thereof?

  • In windows 8 how do you make the bookmarks column "flexible"? I used to be able to make it narrower.

    Windows 8 how do you make the bookmarks column "flexible"?

    Is the problem with the Bookmarks Sidebar -- the one you can open and close by pressing Ctrl+b? It does seem to have a minimum width and won't get narrower than that, but I'm not sure whether you are running into that limitation or whether for some reason you are not getting the resizing arrow when you mouse over the thin border between the sidebar and the page.

  • How do I change the width of column "rating"

    all columns are variable in widht. but not "rating" (stars). How do I change the width of column "rating"?

    Hi Emkaha,
    By the way the column "last played" can be reduced to a size which display the date "incorrect" as well (you'll see only the first number of the date which wouldn't make any sense too, but it is possible).
    True, but if you see date of "1" you will know you are not seeing a full date.  If you see 2 stars, it is a valid value, even if it is not correct.  At least, that is my supposition about why it is designed the way it is.
    Having said that, the extra width in the German version -- the Wertung column is wider than needed for 5 stars -- does seem odd.  In the English version for Windows PC, the Rating width is just enough for 5 stars.  You can report this to Apple via the iTunes Feedback page.

  • How do I save the width and height of a photo for repeated use?

    How do I save the width and height of a picture for repeated use, rather than having to enter it each time in the 'new file' box?
    Thanks,  Ed Jackson.

    It could be that I'm older and have forgotten. I'm now 73 and will admit I have forgotten many things over the years. I have been using Photoshop since Photoshop version 3.  And can not really recall which features or changes were made in ever version of Photoshop I have installed.  Adobe has added many features over the years. The number of bugs introduce has also greatly increased after CS3.  "New Doc Sizes.psp"  in your user id preferences is edited using the two buttons in the new document dialog.
    As for guide lines in new documents Photoshop CS6 or CC seem to add some for video file presets with guide lines.  I do not know how to edit or add guide line to new doc presets. Guide line actions are easy to create. I have also seem some guideline in new documents when I did not expect any perhaps a new bug. Photoshop like most software has bugs. If you do not see Adobe new presets perhaps you copied an old  "New Doc Sizes.psp"  over Adobe's newer default file or Adobe migrared you presets and wand wiped their presets out. There are bugs. Close Photoshop down and rename your current  "New Doc Sizes.psp"  in you user id Photoshop cc preferences folder and start Photoshop it will add a dedault  "New Doc Sizes.psp"  file see if you see Adobe new presets in the new doc pull down when you select video and film...

  • How can I define the possible entries for "invoicing process" at fkkinv_ma?

    At the transaction code fkkinv_ma, I fill in the fields "Date ID" and "Identification" but I have a problem with the field of "Invoicing Process". When I psh theF4 button, there comes no search help. What should I do? Should I define the possible entries first? If I should, how can I define the possible entries for "invoicing process"? How is the customization done?
    Thanks in advance for the answers.

    You have to define them in the IMG 
    Financial Accounting (new)
    Contract Account Recievable and Payable
    Business Transactions
    Invoicing
    Invoice Types
    You have to set up a number range, decide what type of Financial transactions should not be invoiced -- like  Dunning Charges
    then you have to have a developer create the form and form class of invoice.

  • How do you change the position of email sender so that it's on the left (sender[from], subject and date received)

    How do you change the position of email sender so that it's on the left (sender[from], subject and date received)

    In the Thread Pane where your messages are listed?
    You see that bar with the labels "From", "Subject", "Date" and so on? Well, they are buttons. You can click on them to sort your messages. You can also drag them with the mouse left and right to reposition them, and you can drag their ends to change the column widths.
    These are standard computer actions; you can do all of this in Windows Explorer ("My Computer") too.
    In Thunderbird, a right-click on any of these buttons will reveal a pop-up menu where you can select and deselect the columns to control what is shown.
    More here: http://www.ramsden.org.uk/8_How_to_sort.html

Maybe you are looking for

  • Particles question

    Hey all, this is a really easy question: When I making particles with any effect like CC Particle World or Particle Playground etc it puts it on a black background when I apply the effect to the layer I want the particles on. If I apply the effect to

  • Lib32-konqueror-nsplugins and flash doesn't work

    Hallo, I tried the lib32-konqueror-nsplugins. But it doesn't work because: Adobe Flash Player: gtk_clipboard_get(GDK_SELECTION_PRIMARY); failed. Trying to call gtk_init(0,0); (<unknown>:6900): Gdk-WARNING **: Error converting from UTF-8 to STRING: Co

  • Sannot Sync to iPhoto

    If I select the Device Apple TV in iTunes and then select the tab Photos, ITunes cannot see any of iPhoto's library. The Box is blank. If I select Choose Folder, it works as expected. For some reason iTunes cannot access the iPhoto library. All other

  • Macbook pro retina display getting too hot

    Hello, I bought a macbook pro retina display: 2.7 quad core/16GB RAM/1GB Nvidia 650m/768 SSD When I copy files like 20 or 30 GB from an external to my retina the keyboard becomes hot and GPU 141 F (61C). For playing game it becomes more hot!!! I don'

  • Why does call delete crash

    I have iphone 4 with ios7 but call delete is not deleting individual calls and is crashing, did hard reset and complete reset but to no avail, please help