Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2004, 02:11 AM
Authorized User
 
Join Date: Dec 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kaizer Send a message via Yahoo to kaizer
Default JTabbedPane display and input help required...

Hi Folks,

I have set up a JTabbedPane with a few tabs. I would like each tab to hold a set of questions (using JTextArea or JLabel perhaps?). My question is as follows:

Can anyone list out the code ( or point me to some samples on the web) to present one question inside a tabbed pane? I can then replicate that code to present all my questions.

This second part is a bit more involved:

I now need to set up a textfield that accepts double numbers and nothing else. I need to trap the input number perform a calculation and present the answer in another text area. How do i set it up adjacent to the question 1 and how do i trap the input?

If you could point me to some sample source code that does this i'd be grateful.

Thanks in advance.

Kaizer.

P.S. I'm using Java Swing II edition from o'reilly. It's a bit too involved for me. Any suggestions for any other Swing book (for J2SDK version 1.4.2_03) that is on the lines of MR. Ivor Horton's Beginning Java 2?

Thanks again.

Kaizer Billimoria
Bangalore, India
__________________
Kaizer Billimoria
Bangalore, India
 
Old March 27th, 2004, 01:24 AM
Authorized User
 
Join Date: Oct 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mrafaqi Send a message via Yahoo to mrafaqi
Default

hi!
   you can add different JPanel objects to your JTabbedPane object and these may contains your questions. means each panel may contain a JTextField or JTextArea as your required.

make a JTabbedPane with three tabs and so therefore you make make three JPanel objects for three tabs

for example make one as

   JPanel tabOne = new JPanel();
   //set properties of this panel as border, background and etc and components like JTextField and JTextArea objects

   simmilarly make three panels and add them

                              MUHAMMADrizwanAKRAMZIA


 
Old August 22nd, 2004, 05:37 AM
Registered User
 
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi, code is here, generated by JFrameBuilder, http://www.mars3000.com
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QuestionsWin extends JFrame
{
    private JTabbedPane jTabbedPane1;
    private JPanel contentPane;
    //-----
    private JTextArea jTextArea1;
    private JPanel jPanel1;
    //-----
    private JPanel jPanel2;
    //-----
    private JPanel jPanel3;
    //-----
    private JLabel jLabel1;
    private JTextField txf_answer;
    private JPanel jPanel4;
    //-----
    private JPanel jPanel5;
    //-----

    public QuestionsWin()
    {
        super();
        initializeComponent();

        this.setVisible(true);
    }

    private void initializeComponent()
    {
        jTabbedPane1 = new JTabbedPane();
        contentPane = (JPanel)this.getContentPane();
        //-----
        jTextArea1 = new JTextArea();
        jPanel1 = new JPanel();
        //-----
        jPanel2 = new JPanel();
        //-----
        jPanel3 = new JPanel();
        //-----
        jLabel1 = new JLabel();
        txf_answer = new JTextField();
        jPanel4 = new JPanel();
        //-----
        jPanel5 = new JPanel();
        //-----

        //
        // jTabbedPane1
        //
        jTabbedPane1.addTab("Question 1", jPanel1);
        jTabbedPane1.addTab("Question 2", jPanel2);
        jTabbedPane1.addTab("Question 3", jPanel3);
        jTabbedPane1.addTab("Question 4", jPanel5);
        jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        //
        // contentPane
        //
        contentPane.setLayout(new BorderLayout(0, 0));
        contentPane.add(jTabbedPane1, BorderLayout.CENTER);
        //
        // jTextArea1
        //
        jTextArea1.setOpaque(false);
        jTextArea1.setText("Why  ..... ............ ........................ .......... ........... ........ .............. .......... ..............?");
        jTextArea1.setEditable(false);
        jTextArea1.setLineWrap(true);
        jTextArea1.setWrapStyleWord(true);
        //
        // jPanel1
        //
        jPanel1.setLayout(new BorderLayout(0, 0));
        jPanel1.add(jPanel4, BorderLayout.SOUTH);
        jPanel1.add(jTextArea1, BorderLayout.CENTER);
        //
        // jPanel2
        //
        jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        //
        // jPanel3
        //
        jPanel3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        //
        // jLabel1
        //
        jLabel1.setText("Answer:  ");
        //
        // txf_answer
        //
        txf_answer.setText("");
        txf_answer.setToolTipText("Answer the question.");
        txf_answer.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                txf_answer_actionPerformed(e);
            }

        });
        //
        // jPanel4
        //
        jPanel4.setLayout(new BorderLayout(0, 0));
        jPanel4.add(jLabel1, BorderLayout.WEST);
        jPanel4.add(txf_answer, BorderLayout.CENTER);
        //
        // jPanel5
        //
        jPanel5.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        //
        // QuestionsWin
        //
        this.setTitle("QuestionsWin");
        this.setLocation(new Point(176, 100));
        this.setSize(new Dimension(298, 208));
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    //
    // TODO: Add any appropriate code in the following Event Handling Methods
    //
    private void txf_answer_actionPerformed(ActionEvent e)
    {
        // TODO: Add any handling code here

    }

//============================= Testing ================================//
    public static void main(String[] args)
    {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }
        catch (Exception ex)
        {
            System.out.println("Failed loading L&F: ");
            System.out.println(ex);
        }
        new QuestionsWin();
    }
//= End of Testing =
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help required zaeem SQL Server 2000 2 May 28th, 2008 12:48 AM
Some help required ! codenet C# 2005 1 September 24th, 2007 04:01 PM
Validation Framework display of user input dayakarb Struts 0 April 20th, 2007 02:31 AM
Can't display input variable passed on to php code mespejo Beginning PHP 2 November 25th, 2003 03:32 PM
Display bar code in a Form using user input text? phoenixcu Access VBA 1 June 6th, 2003 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.