Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Swing / AWT / SWT
JTabbedPane
Atrus Greyor
,
Ranch Hand
Aug 28, 2004 09:05:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Could anyone give me a small example of a JTabbedPane? It doesn't have to be anything fancy just something that is able to switch between two or more panes.
Gregg Bolinger
,
Ranch Hand
Aug 28, 2004 09:06:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Example(s)
Pat Hays
,
Ranch Hand
Aug 30, 2004 00:28:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Hi,
You may use JFrameBuilder, which will generate Swing examples for you.
http://www.mars3000.com
Here is a simple JTabbedPane 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 = }
Post by:
autobot
This is my favorite show. And this is my favorite tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 1126 times.
Similar Threads
TabPane Events
How do you switch JPanels to be shown within the same JFrame
GridBagLayout not show JTabbedPane right initially but is ok after clicking other tabs
tab style GUIs
seting size of JTabpanel
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:25:56
.