Learning how to use Layout Managers

The code that is included in this post is public code from the SUN tutorials. I am trying to learn how to use the layouts and add individual programs that were created to each component in the layouts.
This is what I am exploring:
I want to have a tabbed layout like the example TabbedPaneDemo located at http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html#TabbedPaneDemo. Below is the code.
In one of the tabs, I want to place a button and report in it. When the button is clicked, I want the report refreshed. Eventually I will be populating an array with data. The report I want to use the example SimpleTableDemo located at http://java.sun.com/docs/books/tutorial/uiswing/examples/components/SimpleTableDemoProject/src/components/SimpleTableDemo.java. Below is the code.
From what I have learned, you can place a container inside a container. So I should be able to place the SimpleTableDemo inside the tab 4 of the TabbedPaneDemo.
If this is indeed correct, then how do I put these two things together? I am getting a little lost in all the code.
Any assistance in helping me learn how to create and use layout managers would be appreciated.
package components;
* TabbedPaneDemo.java requires one additional file:
*   images/middle.gif.
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
public class TabbedPaneDemo extends JPanel {
    public TabbedPaneDemo() {
        super(new GridLayout(1, 1));
        JTabbedPane tabbedPane = new JTabbedPane();
        ImageIcon icon = createImageIcon("images/middle.gif");
        JComponent panel1 = makeTextPanel("Panel #1");
        tabbedPane.addTab("Tab 1", icon, panel1,
                "Does nothing");
        tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
        JComponent panel2 = makeTextPanel("Panel #2");
        tabbedPane.addTab("Tab 2", icon, panel2,
                "Does twice as much nothing");
        tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
        JComponent panel3 = makeTextPanel("Panel #3");
        tabbedPane.addTab("Tab 3", icon, panel3,
                "Still does nothing");
        tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
        JComponent panel4 = makeTextPanel(
                "Panel #4 (has a preferred size of 410 x 50).");
        panel4.setPreferredSize(new Dimension(410, 50));
        tabbedPane.addTab("Tab 4", icon, panel4,
                "Does nothing at all");
        tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
        //Add the tabbed pane to this panel.
        add(tabbedPane);
        //The following line enables to use scrolling tabs.
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    protected JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from
     * the event dispatch thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("TabbedPaneDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Add content to the window.
        frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event dispatch thread:
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //Turn off metal's use of bold fonts
          UIManager.put("swing.boldMetal", Boolean.FALSE);
          createAndShowGUI();
package components;
* SimpleTableDemo.java requires no other files.
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SimpleTableDemo extends JPanel {
    private boolean DEBUG = false;
    public SimpleTableDemo() {
        super(new GridLayout(1,0));
        String[] columnNames = {"First Name",
                                "Last Name",
                                "Sport",
                                "# of Years",
                                "Vegetarian"};
        Object[][] data = {
            {"Mary", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Philip", "Milne",
             "Pool", new Integer(10), new Boolean(false)}
        final JTable table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        if (DEBUG) {
            table.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    printDebugData(table);
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
        //Add the scroll pane to this panel.
        add(scrollPane);
    private void printDebugData(JTable table) {
        int numRows = table.getRowCount();
        int numCols = table.getColumnCount();
        javax.swing.table.TableModel model = table.getModel();
        System.out.println("Value of data: ");
        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + model.getValueAt(i, j));
            System.out.println();
        System.out.println("--------------------------");
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SimpleTableDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        SimpleTableDemo newContentPane = new SimpleTableDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        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();
}

Before I did what you suggested, which I appreciate your input, I wanted to run the code first.
I tried to run the SimpleTableDemo and received the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleTableDemo (wrong name: componets/SimpleTableDemo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader...
there are several more lines but as I was typing them out I thought that maybe the code is not written to run it in the command window. The errors seem to be around the ClassLoader. Is that correct? On the SUN example page when you launch the program a Java Web Start runs. So does this mean that the code is designed to only run in WebStart?

Similar Messages

  • How to use layout managers

    Hi ,
    I designed a JFrame. If i enlrged the frame widow, the components are not arranged properly. How can i arrange them.
    narayana

    the components are not arranged properly.That statement mean absolutely nothing. They are arranged properly according the to the rules of the Layout Manager you are using.
    If it is not layed out the way you want then you need to use a different Layout Manager or combination of Layout Managers. Since you don't define what "properly" means you are on your own.
    Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers

  • Does anyone know if apple's one-to-one program would be a good way to learn how to use logic pro or am I better off going to school to learn audio engineering or something?

    Of course going to school would be a good option, but I want to know if one-to-one is also a good way to learn how to use logic pro. Has anyone been through the one-to-one program for logic pro and can say that they learned how to use logic pro well because of it?

    For sure, one to one training, if given by a tutor who is capable, will hand you the means to build up self-confidence  and will therefore let you operate the hard/software in an intelligent manner, instead of going for the trial and error method which has its pro's and con's too. Once you've passed this beginners phase you will make your own decisions intelligently and then you will also start to get experience and learn even from your mistakes. Something like that in theory and the rest is up to you!
    Have a nice day

  • I am a high school teacher.  My district purchased the entire CC Suite.  Where can I find a tutorial in book form to learn how to use your products?  Do you all provide free book samples to teachers?

    I am a high school teacher.  My district purchased the entire CC Suite.  Where can I find a tutorial in book form to learn how to use your products?  Do you all provide free book samples to teachers?

    Good day!
    This is a user to user Forum, so you are not really addressing Adobe here, even though some Adobe employees thankfully have been dropping by. (edit: Actually they are more likely to frequent the regular Photoshop Forum.)
    Regards,
    Pfaffenbichler

  • I am very new to mac products, I have a Mac Pro 13" I  need to learn how to use it ? looking video courses any will helpI

    I am very new to mac products, I have a Mac Pro 13" I  need to learn how to use it ? looking video courses any will help .....

    Go to www.apple.com for a start. See, also, Mac Basics.

  • I need to learn how to use all about java & mysql...help me!

    I have a situation here, I need to learn how to use java with mysql
    . Can I connect to a MYSQL DB with servlets?
    how can I build an e-mail server with java (no matter how difficult)
    please, I need help, and I really apreciate your help.
    thank you very much!!

    I have a situation here, I need to learn how to use
    java with mysql
    . Can I connect to a MYSQL DB with servlets?Yes... documentation to help you connect to any database can be found at http://java.sun.com/products/jdbc. To connect to MySQL, you'll need drivers (sourceforge.net), and the specific connection URL for those drivers will be included in the documentation.
    how can I build an e-mail server with java (no matter
    how difficult)If you're fairly new to JSP/Servlets, you may be in over your head here, since an email server is no easy application to code. Here's a link to the source code for the JAMES project... Apache's Java email server... maybe you can find some useful information there...
    http://www.ibiblio.org/pub/packages/infosystems/WWW/servers/apache/jakarta/james/source/

  • Best place to go to learn how to use my iPad mini?

    Where can you go online to learn how to use the iPad mini?

    Here's the User Guide:
    iPad User Guide - For iOS 7.1 SoftwareMar 10, 2014 - 25 MB
    There are other good books available, but the User Guide is an excellent reference.

  • I need to learn how to use Illustrator CS6

    I have tried to access both the help topics and the video tutorials for Illustrator CS6.  Help topics always have no listing for learning how to use the program.  And the video tutorials will not run.

    What does that mean "will not run?" Any error? Doesn't show? No sound?
    Which system? Which browser? Which page exactly?

  • What a good book to learn how to use Apple's software professionally

    I have a MAC Mini, need to learn how to use Apple's sofeware professionally!  Like how to put headers on a spreadsheet!

    Hello Eva,
    For a book...
    http://shop.oreilly.com/product/9780596157593.do
    For Tutorials...
    https://www.apple.com/iwork/tutorials/#numbers-hero

  • Want to learn how to use the imac.  is there tutorials or something that can start me off?

    is there places that can help me to learn how to use the imac to the best of its ability?

    This has tutorials  http://www.apple.com/findouthow/mac/

  • How Do I Learn How To Use The Terminal?

    Are there any places to learn how to use the command line in Terminal?

    Whywutt,
    Thank you very much.
    Its appreciated.

  • Is it possible to make a javafx ui application without using layout managers ?

    I want to make an user interface application without using layout managers. In my previous attempt i made an application in java swing. There i used the setBounds() function. Is there any function like setBounds() in javafx ?

    There really isn't any more to it than that.
    Again, I have no idea why you would do things this way (either in JavaFX or in Swing), but:
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.Pane;
    import javafx.stage.Stage;
    public class ManualPositioningExample extends Application {
        @Override
        public void start(Stage primaryStage) {
            final Pane root = new Pane();
            final Button button = new Button("Click me");
            final Label label = new Label("A Label");
            final TextField textField = new TextField();
            root.getChildren().addAll(button, label, textField);
            label.relocate(25, 25);
            textField.relocate(75, 25);
            textField.setPrefSize(100, 20);
            button.relocate(25, 50);
            button.setPrefSize(150, 20);
            Scene scene = new Scene(root, 400, 200);
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            launch(args);

  • I need to learn how to use jump lists.

    '''bold text'''I need to learn how to use jump lists. acording to all that I have muddled thru my ereader will only download books I have purchased and free ones if I use a jump list. I don't know how. If this is the correct method for ereaders downloads someone please explain it, simply to me. I have a reader I am totally unable to use. I have read the manual many times. That info doesn't work.

    How is that related to Firefox support?

  • Javascript error on - Help - Learn how to use Numbers with this online...

    I am trying to find out more about Numbers. I am using iTunes 9.1.1 on a Vista PC. I get a Javascript error in Internet Explorer 8 when I try to access:
    Help - Learn how to use Numbers with this online resource.
    http://help.apple.com/numbers/1.0
    The link redirects to the following page:
    http://help.apple.com/iwork/safari/interface/#tan727163ed
    The above page is blank except for boxes for Keynote Help, Pages Help, Numbers help, and a blank input field that seems to do nothing. Here is the Javascript error message from Internet Explorer 8:
    Webpage error details
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
    Timestamp: Tue, 1 Jun 2010 20:55:54 UTC
    Message: This command is not supported.
    Line: 1
    Char: 41589
    Code: 0
    URI: http://help.apple.com/iwork/safari/interface/javascript.js

    Link also does not work for me in WIN 7 with IE8. However, it does work in Chrome in WIN 7. It also works in Safari on my G4. Suggest you try Chrome or it may work in another browser like FireFox or Safari in Vista.

  • Where do I go to learn how to use Terminal?

    I need to learn how to use Terminal. I learn best via video tutorials. Wondering if Apple has anything that will help?

    Thanks to you both TeenTitan and leroydouglas.
    As a web designer I decided to make the leap to HTML5 recently and have been collecting TONS of wonderful links to help me get up and running. HTML5 is a monumental leap compared to the transition I had to make from HTML 3.2 to 4 and then from 4 to XHTML 1.0. I was greatly encouraged to find the WebDev community embracing HTML5 Boilerplate and thought life would actually be simpler even when I heard Divya Manian encourage developers to be sure to use Paul Irish's Build Script which comes with HTML5 Boilerplate. As I watched his video, I realize as a Mac user that while there may be an alternative way to work with the Build Script I may not know how to do it properly so I'd best make peace at long last with Terminal. I don't want to run the script on a site and wonder if I didn't use Build Script properly.
    If interested you can learn about HTML5 Boilerplate here.
    Here is the YouTube video I mentioned about the demo for Build Script and its use in Terminal.
    I will definitely bookmark all your links and review them soon.

Maybe you are looking for

  • The conversion from a PDF to Word is terrible, how do I get my money back

    I just bought the year subscription to the basic service, allowing me to convert PDF files to Word and Excel. Post export, the file is all but ruined. Some things are underlined and typed out, while other seemingly random parts are pasted in like a p

  • Parameter dialog

    im working on a vb.net app in VS.net2005 with crystal reports XI. i would like to disable the parameter dialog if at all possible? if not i would like to be able to get the parameter dynamic values added in the report to show in the dialog..?

  • How to send a picture to facebook directly

    How to send a picture from iphone to facebook directly

  • What is compete DCA monitoring tool?

    about every 5 minutes a warning window appears saying DCA monitoring tool encountered a problem and needs to close. I have no idea what to do to repair this???? I send Microsoft an error report. Then it goes away.

  • BWoH 7.4 new Bex Feature

    Hi All, Any one of you worked on any of the following new topics: Multidimensional Exception Aggregation Current Member variable Please let me know where can I find these options, I tried but don't see these options it the respective places. A screen