JTable size problems due to layout/grid...how can I fix?

This is my code. When the button "Modify Entries" is pressed, it shows a JTable that imports a file called, "entries.data". The items in this file can be read and saved using this program. The problem is that the table is so small when it first opens. How can I set all my buttons to the very bottom of the form and make the table take up more space at the top? It looks to me as if this layout is treating it with the same dimensions as the buttons'.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.*;
import java.io.*;
public class CPT extends JPanel implements ActionListener
    protected JButton ModifyEntriesButton, ViewEntriesButton, SearchEntriesButton, SaveButton, BackButton;
    private final static String newline = "\n";
    private DefaultTableModel model;
    public CPT ()
        super (new GridLayout (10, 0));
        model = new PropertiesModel ("entries.data");
        ModifyEntriesButton = new JButton ("Modify Entries");
        ModifyEntriesButton.setVerticalTextPosition (AbstractButton.TOP);
        ModifyEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
        ModifyEntriesButton.setToolTipText ("Click this button to modify database entries.");
        ModifyEntriesButton.setMnemonic (KeyEvent.VK_M);
        ModifyEntriesButton.setActionCommand ("ModifyEntries");
        ModifyEntriesButton.addActionListener (this);
        ViewEntriesButton = new JButton ("View Entries");
        ViewEntriesButton.setVerticalTextPosition (AbstractButton.CENTER);
        ViewEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
        ViewEntriesButton.setToolTipText ("Click this button to add view all database entries.");
        ViewEntriesButton.setMnemonic (KeyEvent.VK_V);
        ViewEntriesButton.setActionCommand ("ViewEntries");
        ViewEntriesButton.addActionListener (this);
        SearchEntriesButton = new JButton ("Search Entries");
        SearchEntriesButton.setVerticalTextPosition (AbstractButton.BOTTOM);
        SearchEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
        SearchEntriesButton.setToolTipText ("Click this button to search through all database entries.");
        SearchEntriesButton.setMnemonic (KeyEvent.VK_S);
        SearchEntriesButton.setActionCommand ("SearchEntries");
        SearchEntriesButton.addActionListener (this);
        SaveButton = new JButton ("Save");
        SaveButton.setVerticalTextPosition (AbstractButton.TOP);
        SaveButton.setHorizontalTextPosition (AbstractButton.RIGHT);
        SaveButton.setToolTipText ("Click this button to save database entries.");
        SaveButton.setMnemonic (KeyEvent.VK_S);
        SaveButton.setActionCommand ("Save");
        SaveButton.addActionListener (this);
        BackButton = new JButton ("Back");
        BackButton.setVerticalTextPosition (AbstractButton.BOTTOM);
        BackButton.setHorizontalTextPosition (AbstractButton.RIGHT);
        BackButton.setToolTipText ("Click this button to return to the main menu.");
        BackButton.setMnemonic (KeyEvent.VK_B);
        BackButton.setActionCommand ("Back");
        BackButton.addActionListener (this);
        add (ModifyEntriesButton);
        add (ViewEntriesButton);
        add (SearchEntriesButton);
    class PropertiesModel extends DefaultTableModel
        public PropertiesModel (String filename)
            addColumn ("Item Number");
            addColumn ("Description");
            addColumn ("Price");
            //Fill model with data from property file
            Properties props = readFile (filename);
            if (props != null)
                Enumeration coll = props.keys ();
                while (coll.hasMoreElements ())
                    String property = (String) coll.nextElement ();
                    String value = props.getProperty (property, "");
                    addRow (new Object[]
                        property, value
    private Properties readFile (String filename)
        try
            Properties props = new Properties ();
            props.load (new FileInputStream (filename));
            return props;
        catch (IOException ioe)
            return null;
    private boolean saveFile (String filename)
        try
            Properties props = new Properties ();
            for (int i = 0 ; i < model.getRowCount () ; i++)
                props.put (model.getValueAt (i, 0), model.getValueAt (i, 1));
            props.store (new FileOutputStream (filename), null);
            return true;
        catch (IOException ioe)
            return false;
    public void actionPerformed (ActionEvent e)
        if ("ModifyEntries".equals (e.getActionCommand ()))
            removeAll ();
            add (new JScrollPane (new JTable (model)), BorderLayout.CENTER);
            add (SaveButton);
            add (BackButton);
            invalidate ();
            updateUI ();
        if ("ViewEntries".equals (e.getActionCommand ()))
            removeAll ();
            add (BackButton);
            invalidate ();
            updateUI ();
        if ("SearchEntries".equals (e.getActionCommand ()))
            removeAll ();
            add (BackButton);
            invalidate ();
            updateUI ();
        if ("Back".equals (e.getActionCommand ()))
            removeAll ();
            add (ModifyEntriesButton);
            add (ViewEntriesButton);
            add (SearchEntriesButton);
            invalidate ();
            updateUI ();
        if ("Save".equals (e.getActionCommand ()))
            if (saveFile ("entries.data"))
                JOptionPane.showMessageDialog (null, "File saved successfully.");
            else
                JOptionPane.showMessageDialog (null, "File could not be saved!");
    // Create the GUI and show it. For thread safety,
    // this method should be invoked from the
    // event-dispatching thread.
    private static void createAndShowGUI ()
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated (true);
        //Create and set up the window.
        JFrame frame = new JFrame ("Swisha Computer House");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        JComponent newContentPane = new CPT ();
        newContentPane.setOpaque (true); //content panes must be opaque
        frame.setContentPane (newContentPane);
        //Display the window.
        frame.pack ();
        frame.setSize (300, 300);
        frame.setVisible (true);
    public static void main (String[] args)
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater (new Runnable ()
            public void run ()
                createAndShowGUI ();
}Hey, and if anyone knows how to get the first column's numbers from the file to show up in descending order (1 through to, say, 500), please let me know.
Thank you for any help.

It looks to me as if this layout is treating it with the same dimensions as the buttons'.Thats the way a GridLayout works.
Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers. You can mix an match individual Layout Managers to get the effect desired.
I would suggest you need to change your design. Your code for continually removing and adding components is not the best design. You should probably have a panel with all your buttons. Then you would have different panels for each of your sub functions. The display of these panels would be controlled by a Card Layout. The tutorial has working examples of this.
You can't use a Properties file to save data from the table (at least not the way you are attempting to use it). I gave you a solution in your last posting.

Similar Messages

  • I cannot move photos from iphone to MacBook.  I get an error message that says: Error downloading image. iPhoto cannot import your images because there was a problem downloading an image. How can I fix/remedy this?

    I am receiving an error message every time I plug my iPhone 4S into my MacBook: Error downloading image. iPhoto cannot import your images because there was problem downloading an image.  How can I fix/remedy this?

    try Image Capture - in your applications folder
    LN

  • I updated the OS on my new ipad and now can't even start a sync with my win7 PC. I had no problem before the OS upgrade - How can I fix it?

    I never had a problem synching before I updated the OS on my new ipad and now I can't even start a sync.  I have a win7 PC and use the ipad every day. How can I fix this so it syncs again? 

    I don't have my computer in front of me to check, but when you connect your iPad to your computer and open iTunes, there are options on what to sync. To manually manage music and other options.
    If you can sync movies but not music then it suggests that the connection is good, so that part works. Which means it just may be a setting in iTUnes (and I mean iTunes on the computer, not the iPad)

  • My iPhone will not synch due to error 1140, how can I fix this?

    How can I connect my iPhone to my Mac computer without error? Error 1140 keeps appearing

    Download and install the iPhoto 9.4.1 update, which was just released today. It may be the answer to your problems:
    http://support.apple.com/kb/DL1598

  • My marketplace has lost it's Layout! How can I fix the problem?

    Hi!
    Somehow on 4th March 2015 I experienced a mixture of two problems already known in the forum:
    a) https://support.mozilla.org/de/questions/1039948
    b) https://support.mozilla.org/en-US/questions/1027288
    First I was not able to get into FF Marketplace using the Marketplace App. It did not move on from the loading screen (so slightly different from b)) Marketplace worked fine when I used the browser like Ralph did suggest in a). Then I deleted the user data of the Marketplace-App in the Application manager. Since then I got into Markeplace again using the App, but Marketplace lost it's Layout. Using the Browser for accessing Marketplace works, but doesn't influence the app.
    My phone is Alcatel One Touch Fire E. Firefox OS 1.3.0.0 The last app I updated was BibleZ.
    I think resetting the phone could help. But instead of loosing all my data I would rather just use the browser to access marketplace. So could there be another possibility to solve the problem, so that I can use the Marketplace app again? When I had problems with displaying websites, I deleted the cookies and it worked again, but it is not possible in Marketplace app, is it?
    Thank's

    Thank's for your reply Ralph.
    My Problem is solved now, because I updated to Firefeox OS 2.0. The Update was just recently released.

  • HT201210 i have problem whit "do not diturb" how can i fix it?

    my do not distorb aplication from my iphone 4s is not working,i traid to restore the iphone ,and is not working to restore

    Do not disturb has problems since 2013. It was said to be fixed on January, 6.

  • ITunes crashes due to "audioscrobbler". How can I fix this?

    I deleted my last.fm plug in, deleted and reinstalled iTunes and restarted my computer but it still doesn't work. It just instantly unexpectedly quits, apparently due to an audioscrobbler plug in that I can't find anywhere on my computer.

    http://support.apple.com/kb/TS1538

  • Flash Animations and Movies are lagging after having played a flash game which was graphics intense heavy and frequently refreshed which caused lags, how can I fix this lagging problem for Flash?

    On June 30th, I was playing a game called Lil Einstein's Manhattan project over at Newgrounds.com and the game although fine at first, later on in the advanced levels of the game, started to cause my browser to lag intensely and heavily. Now, when I try and watch other flash movies and animations, the flash doesn't run as smoothly, there are skips in the flash animations and movies, and it slows down.
    I tried scan disks, I tried defragmenting my computer, I tried uninstalling and re-installing Firefox.. Nothing worked to restore the Flash.
    But when I view Flash movies and animations on Internet Explorer, they run fine... but not anymore on Firefox.
    Other Firefox users who have played this game also reported problems as well..
    How can I fix my Firefox Browser and return the Flash running to normal?
    == This happened ==
    Not sure how often
    == June 30th, 2010

    If you have already scanned PC with an updated Anti-Virus and still the issue exists then I would suggest some troubleshooting techniques to resolve this problem:
    Update browser
    Remove unwanted Add-ons
    Remove unwanted Tool-bars
    Repair Registry
    Repair ActiveX objects and shared DLLs
    In case of facebook and Zynga I would suggest to Check for Problems with your Internet Connection.Try to Update Java and Reduce the Number of Running Internet Applications.
    Sometimes Multimedia content lag due to Hardware Acceleration, so disabling Hardware Acceleration should fix your problem.
    Open Flash Video in browser
    Right click on Video Player | Settings
    Open Display Panel
    Uncheck Enable Hardware Acceleration
    If issue still exists then you can find some more techniques described in detail here:
    http://www.shockwaveflashcrash.com/Easiest-fix-for-shockwave-flash-plug-in-Crash.html

  • Thunderbird has ecountered a problem and must close...how can I fix this?

    When I try to open Thunderbird on my Windows XP, I get a box saying "Thunderbird has encountered a problem and must close. How can I fix this problem so I can access my emails?

    Did you install MacKeeper?  If you did, remove it:
    https://discussions.apple.com/docs/DOC-3036
    MacBook Pros don't run iOS.  Go to Apple menu -> About This Mac and tell us your Mac OS X version.
    Tell us also if you are backed up.
    Tell us also if you have seen four language screens telling you to restart.

  • Hi   I've lost the streaming icon (inverted triangle) on my iPhone4S and iPad4 since I downloaded IOS7.  How can I fix this?

    Hi.  Since I downloaded IOS7 I have lost the streaming "triangle" on my iPhone4S and iPad (4th generation).   It's still on my original 1st Generation iPad (I haven't updated the IOS) hence I'm certain the problem relates to IOS7.  How can I fix this?
    Doody1955

    If you share an Apple ID, both of your phone numbers should be linked to that ID. You should be able to use your phone number as well. My wife, my daughter and I all share an Apple ID for purchases, and we each text from our iOS devices using our own iPhone numbers.
    When iOS 6 came out, you were able to link the phone number with your Apple ID to use for Messages and FaceTime. You will need to sign out of messages on all devices and then start the process all over again.
    Take a look at this.
    iOS and OS X: Link your phone number and Apple ID for use - Support

  • When I try to make a new video, a window comes up that says,"The operation could not be completed," and then under it, it says,"No other information is available about the problem," what is happening and how do I fix it?

    when I try to make a new video, a window comes up that says,"The operation could not be completed," and then under it, it says,"No other information is available about the problem," what is happening and how do I fix it?

    Hi
    And without info - it's near to impossibly to help. Try my general troubleshooting note:
    Troubleshooting note
    When iMovie doesn't work as intended this can be due to a lot of reasons
    iMovie Pref files got corrupted - trash it/they and iMovie makes new and error free one's
    problem in iMovie Cache folder - trash Cache.mov and Cache.plist
    Creating a new User-Account and log into this
    This forces iMovie to create all pref. and cache files new and error free
    Event or Project got corrupted - try to make a copy and repair
    a Codec is used that doesn't work (even though iMovie and/or iDVD tries to / they fail in the end)
    version miss match of QuickTime Player / iMovie / iDVD
    preferences are wrong - Repair Preferences
    other hard disk problem - Repair Hard Disk (Disk Util tool - but start Mac from ext HD or DVD)
    External hard disks - MUST BE - Mac OS Extended (hfs) formatted to work with Video
    ( UNIX/DOS/FAT32/Mac OS Exchange - works for most other things - but not for Video )
    USB-flash-memories - usually do not work
    Net-work connected hard disks - usually do not work (most often not fast enough and WRONGLY FORMATTES as DOS etc)
    iPhoto Library got problems - let iPhoto select another one or repair it. Re-build this first then try to re-start iMovie. When iMovie starts-up it first look trough this iPhoto library and if faulty it all Halt’s.
    This You do by
    First -  close iPhoto
    Secondly - on start up of iPhoto - Keep {cmd and alt-keys down}
    Thirdly - now select all five options presented
    THEN - WAIT a long long time (>20 hours are not strange)
    free space on Start-Up (Mac OS) hard disk to low (<1Gb) - I never go under 25Gb free space for SD-Video (4-5 times more for HD)
    external devices interferes - turn off Mac - disconnect all of them and - Start up again and re-try
    GarageBand fix - start GB - play a few notes - Close it again and now try iMovie
    Screen must be set to million-colors
    Third-party plug-ins doesn't work OK
    Run "Cache Out X", clear out all caches and restarts the Mac
    Let Your Mac be turned on during one night. At about midnight there is a set of maintenance programs that runs and tidying up. This might help
    Turn off Your Mac - and disconnect Mains - for about 20-30 minutes - at least this resets the FireWire port.
    In QuickTime - DivX, 3ivx codec, Flip4Mac, Perian etc - might be problematic - temporarily move them out and re-try
    (I deleted the file "3ivxVideoCodec.component" located in Mac HD/Library/Quicktime and this resolved my issue.)
    buenrodri wrote
    I solved the problem by removing the file: 3ivxVideoCodec.component. after that, up-dated iMovie runs ok.
    Last resort: Trash all of iMovie and re-install it
    Yours Bengt W

  • Since upgrading to 8.0 I can no longer print from Mapquest Classic. I an from IE. How can I fix that? ALSO I don't like the new layout. How can I go back to my pervious version?

    Since upgrading to 8.0 I can no longer print from Mapquest Classic. It's not a Mapquest problem it's a Firefox problem as I am able to print using IE. I haven't encountered any other sites problems yet but I'm sure it's to come if I don't get this fixed. I need to be able to print. How can I fix this?
    I also do not like the new layout. How can I go back to my previous version?

    What precisely do you mean by deleting the podcast app from both the phone and Mac? I have deleted the podcast app from my phone but on my Mac in iTunes->iPhone->Apps it shows up albeit with a button labelled "Install". I've resynced 3 times and when I try to access my Podcast playlist in the Music app, I still get a message telling me that podcasts have moved to the Podcast app. I'm really sick of some of the changes Apple  has made to their software.

  • Some websites display in a very basic format in Mozilla, but are fine in Explorer. This is a recent problem. How can I fix this?

    Recently Mozilla is having problems displaying some websites. Previously these website displayed fine, and in Internet Explorer they still displays them fine.
    For example. http://www.yr.no/ displays few graphics, and all the text is in times new roman font. The size of the font varies and things are bulleted. Links appear blue and underlined, and the rest of the text is black. The sites are now very plain and have none of their previous detail. How can I fix this?

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    * Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    * Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    Can you attach a screenshot and post a link?
    *http://en.wikipedia.org/wiki/Screenshot
    Use a compressed image type like PNG or JPG to save the screenshot and make sure that you do not exceed the maximum file size (1 MB).
    You did check the Windows Accessibility settings in the Control Panel?

  • On my iPad 2 I can nolonger view maps.  It says there are JavaScript errors.  How can I fix this problem?

    On my iPad 2 I can nolonger view maps.  It says there are JavaScript errors.  How can I fix this problem?

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."

  • I am experiencing problem (the installation does not start) when I try to install ArchiCAD 17 Educational on my mac. I am using Yosemite. How can I fix it?

    I am experiencing problem (the installation does not start) when I try to install ArchiCAD 17 Educational on my mac. I am using Yosemite. How can I fix it?

    You need to contact the developer/manufacturer directly to determine if their product is compatible w/Yosemite.  It is not listed on their system requirement website:
    Mac OS X 10.9 Mavericks
    Mac OS X 10.8 Mountain Lion
    Mac OS X 10.7 Lion
    Mac OS X 10.6 Snow Leopard*
    Note: ArchiCAD 17 is the last version of ArchiCAD to support Mac OS X 10.6
    Only case insensitive file-system volumes are supported.
    http://www.graphisoft.com/support/system_requirements/archicad17.html

Maybe you are looking for

  • Oracle 10G: Creation of a new scheduled job gives error

    When a new job is being created, it keeps giving this error. The job does not exist and has never been created. I have checked if such a job exists using EM and did not find one. Any help on this is really appreciated. Some entry is there in some tab

  • Intel Mac Mini & webcam

    I have a Mini and would like to use a webcam on it. I use a P/S2 keyboard and mouse and a non-Apple monitor so i can switch between the Mini & PC. I have tried using my PC cam but the Mini doesn't see it. Any ideas? This is a cross-post from the Came

  • Credit/debit values in report not displaying properly

    HI friends,                 In one of my report i need to get credit and debit and credit/debit values for the key due date>365 days. I have given the restriction on net due date as <key due date-365.But all the customers in the range above 365 days

  • What is the problem in this code

    hi im tring to ftech mutliple reords to tabuler form text item i write this code but its only fetch values for first record in the text item and do not fetch to other records in the same text item Declare cursor c is select distinct group_a from sc_m

  • Performance issue: Adding a new product line to existing Quote calls pricing engine for existing line a well

    Hi All, I need some assistance for my below query... If there are already existing some product/quote lines on the quote and then we try to add another new product/quote line to this quote , then  it is taking more time to add the product. As per my