Results 1 to 15 of 15
  1. #1
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default Combining these 2 projects

    java.sun.com/docs/books/tutorial/uiswing/examples/components/index(dot)html#table[/url]


    Im trying to add the tabs from "TabbedPanelDemo" to "TextSamplerDemo"


    I am sure i will fig it out eventually but, if someone is up to throwing it up on pastebin or in a reply ...i will study it in and out.

  2. #2
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    i need one more post to post my resource list, hello Java , goodbye Pussy :)

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Components are java gui elements. Container components like tab panes, jpanels, etc... can contain other components. In other words, you can put things like JTextAreas inside tab panes. The normal syntax is something like the following:
    Java Code:
    ...
    JTextArea textArea = new JTextArea();
    JPanel panel = new JPanel();
    panel.add(textArea);
    ...
    This syntax is true for most components and should work in your case with a text area and a tab pane -- add the text area to the specific pane you want it on.

  4. #4
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    mmm okay im doing some reading right now but, it just looks a lil scary


    like i cant just cut and paste in the tabs bc i know there has to be some of the same elements in the text demo already ...

    thanks for the help . i think im gonna throw it up on paste bin as well bc im still unsure about where to paste it in .

  5. #5
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    heres the paste bin ....i know im messin up bad but, i tried to throw that text demo in pane 2 it obv dint work.

    If anyone has anyone can help fix it up or has some comments feel free to chime in and i will back track what was done so i wont have this problem again .

    http://pastebin.com/m7b9cdf31

    now that i can post links the code for both the demos im working off can be found at :
    http://java.sun.com/docs/books/tutor...mplerDemo.java
    and
    http://java.sun.com/docs/books/tutor...dPaneDemo.java
    Last edited by fresh83; 12-27-2009 at 03:27 AM.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Its really not that scary. This took about 4 minutes to write:
    Java Code:
    package fun;
    
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    
    /**
     * @author Steffen Gates
     */
    public class Tabs {
        public static void main(String[] args) {
            new Tabs();
        }
    
        JFrame window;
        JTextArea textArea1, textArea2;
        JTabbedPane tabPane;
    
        public Tabs(){
            window = new JFrame();
            textArea1 = new JTextArea();
            textArea1.setName("Text Area 1");
            textArea1.setText("The quick brown mac jumped over the lazy IBM.");
            textArea2 = new JTextArea();
            textArea2.setName("Text Area 2");
            textArea2.setText("This is some more text.");
            tabPane = new JTabbedPane();
    
            tabPane.add(textArea1);
            tabPane.add(textArea2);
    
            window.add(tabPane);
    
            window.setSize(640, 480);
            window.setLocationRelativeTo(null);
            window.setDefaultCloseOperation(window.EXIT_ON_CLOSE);
            window.setVisible(true);
        }
    }
    Your experiments are WAY too complicated. Simplify things, get one thing working at a time. Plopping 500 lines of code into another 500 lines of code will always result in mess. Start small, baby steps. Many of us have spent 5 or 10 years learning this stuff, you cannot do it all overnight.

  7. #7
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    >:O thats why i thought it be easier to drag and drop the tabs into the text demo ...and yea i realize that but, im on a time schedule. Still would like to see them combined to learn from but, im reading through suns tuts on swing right now .

  8. #8
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    ill fig out how to plug in everything else myself but, still open for more info to who ever wants to play teacher :)

  9. #9
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    If you look at my example, you should be able to extend it to yours. I did what you are trying to do but very simply. If your entire text editor is in a JPanel or JPane, you can simply copy/paste the entire panel into the JTabbedPane. However, you will also need to declare and import everything that your text editing JPanel/pane does, which is where it can get messy, esp. if you have many methods. The other idea (and prob. a much simpler one) is to simply wrap a tabbed pane around the existing code in the text editor class. Either way, start with a simply example that works (like mine) and build on it a bit at a time. Good Luck!

  10. #10
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    Well what im doing is putting together a program for experience.

    What i wanted to do is put together a program that will hold all the info about the android app. So far ive decided i want :

    Password protection - just 1 password at the start so as to not get in the wrong hands.


    Then some tabs

    Tab 1 : Company overview with a menu that people can click on different features and see a pic and some text .

    Tab 2: Employee and Contacts list - We have around 200 ppl voulunteered to help out plus teachers, lawyers, advertisers and a board of advisors so i wanna make a spreadsheet with all this info.


    Tab 3: A tree hierarchy of our business plan as of now . possibly editable but , at least viewable upon click.


    and thats it as of now . id like to play with changing the background of swing as well or making my own GUI .



    youll be seeing me around here alot im guessing , thanks for your help.

  11. #11
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    Your example works but, theres not much to connect the dots between the 2 projects bc you coded a bit diff from suns examples.

    I understand the border layout now , and i want the tabs to be @ PAGE_START.

    ...so is it standard to put the border layout in the tabs or do you put the tabs in border layout?


    import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;

    public class BorderLayoutDemo {
    public static boolean RIGHT_TO_LEFT = false;

    public static void addComponentsToPane(Container pane) {
    //Why is there a exclaimation after the if?
    //What is jlabel?
    //What is this statement doing . (it seems to be getting the bored layout and adding a pane
    //but , i dont uderstand why this would be a if statement.
    if (!(pane.getLayout() instanceof BorderLayout)) {
    pane.add(new JLabel("Container doesn't use BorderLayout!"));
    return;
    }

    if (RIGHT_TO_LEFT) {
    pane.setComponentOrientation(
    java.awt.ComponentOrientation.RIGHT_TO_LEFT);
    }


    JButton button = new JButton("Button 1 (PAGE_START)");
    pane.add(button, BorderLayout.CENTER);

    //Make the center component big, since that's the

    button = new JButton("Button 2 (CENTER)");
    button.setPreferredSize(new Dimension(200, 100));
    pane.add(button, BorderLayout.PAGE_START);


    button = new JButton("Button 3 (LINE_START)");
    pane.add(button, BorderLayout.LINE_START);

    button = new JButton("Long-Named Button 4 (PAGE_END)");
    pane.add(button, BorderLayout.PAGE_END);

    button = new JButton("5 (LINE_END)");
    pane.add(button, BorderLayout.LINE_END);
    }

    /**
    * 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("BorderLayoutDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    //Set up the content pane.
    addComponentsToPane(frame.getContentPane());
    //Use the content pane's default BorderLayout. No need for
    //setLayout(new BorderLayout());
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {
    //UIManager.setLookAndFeel("com.sun.java.swing.plaf. windows.WindowsLookAndFeel");
    UIManager.setLookAndFeel("javax.swing.plaf.metal.M etalLookAndFeel");
    } catch (UnsupportedLookAndFeelException ex) {
    ex.printStackTrace();
    } catch (IllegalAccessException ex) {
    ex.printStackTrace();
    } catch (InstantiationException ex) {
    ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
    ex.printStackTrace();
    }
    /* Turn off metal's use bold fonts */
    UIManager.put("swing.boldMetal", Boolean.FALSE);

    //Schedule a job for the event dispatch thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }
    }

  12. #12
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    ...so is it standard to put the border layout in the tabs or do you put the tabs in border layout?
    It totally depends on your design. I sketch a design on paper and then figure out how I could make it work on the screen. Remember that border layout is just one of MANY layout managers. Not all projects are suited for border layout. 95% of the time, I don't use any what-so-ever, rather, I use NetBeans' built in gui builder (which uses absolute layout? Can't remember). Anyway, with NB, gui code is written for you, and you can simply drag'n'drop components into the correct place, then edit attributes. Coding the layouts from scratch can be VERY time consuming and tedious to get just right.

    I don't know what your gui is supposed to look like, but if I had an interface dominated by tab panes, then I would use no outer layout manager, and simply put the tab panel into the window. If the content of the tab is so complex that it needs a layout manager, then you can do that (for example, a couple rows/columns of buttons and a few text fields). However, if its simple, like a button and a text area, don't bother with fancy layout, it isn't needed. You can always put things into panes and panels to divide them up too.

  13. #13
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    Right now im using Dr. Java bc Netbeans just has to much shit for just begininng. I was scared to press or name anything and theres just to many ways 2 fuck up . Eventually i will transition but, both developers i ask for assitance at night agreed since this is my first language besides web languages i should learn the hard way doing code and transition into netbeans/eclipse. Plus ive always liked playing with code over programs like dreamweaver ect. ... i saw the sec about absolute positioning but , i haven't had a chance to read it yet.

  14. #14
    gcampton Guest

    Default

    If you know all the basics to java, (up to inheritence, hashtables, arraylists, treemaps file reading, exception handling etc) then I think at this stage you should move onto netbeans or eclipse. they both come with tutorials and once you spend a day or less (couple hours) learning those, it's not something you forgot easily.

    This was how I approached it, and seemed to be quite easy. I felt the same way, in that I did not want to have to spend a few weeks learning an IDE when I had more important things to do (eg. learn java). But I think if you don't know the basics then a lot of basic settings that the IDE's have will seem very oblivious.

    Netbeans has the advantage of GUI builders... which saves a lot of typing. But then if you don't know the basics I probably would not be jumping into swing and Gui's just yet as it may complicate things. *just my 2 cents.
    Last edited by gcampton; 12-28-2009 at 02:04 AM.

  15. #15
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    I would not recommend trying to decipher Sun's tutorial programs because they can get very confusing for newbies. Also ! means not, so !true could be read as "not true" which means false. The code if (!(pane.getLayout() instanceof BorderLayout)) means that it gets the layout of the pane, checks if is is borderlayout, and then applies not, !, to it so if it is border layout the if statement would be if(!true). Basically the if statement makes sure the pane uses borderlayout.

Similar Threads

  1. Replies: 0
    Last Post: 04-16-2009, 10:51 PM
  2. Replies: 2
    Last Post: 04-03-2009, 04:03 PM
  3. combining two separate codes into one
    By jaiminparikh in forum Advanced Java
    Replies: 22
    Last Post: 02-18-2009, 06:35 PM
  4. Combining Individual Sounds - Urgent
    By JDCAce in forum Advanced Java
    Replies: 4
    Last Post: 12-05-2008, 06:17 AM
  5. Help combining loops into 1 program.
    By kewlgeye in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •