Monday, March 3, 2014

Panels and Layouts In Swings
















Hi All,
















I am struggling to get the the Tabbed Panel















Which has















1)two sub panels each one on left and one on the right















And i need to get one event performed like if i click on the submit button i need to get a list on the right hand side in one panel
















Can any one please help me out to resolve this issue
















Here is















import java.awt.*;















import java.awt.event.*;















import javax.swing.*;















import javax.swing.text.GapContent;
















public class Example extends JFrame















{















JTabbedPane tabbedPane = new JTabbedPane();
















JPanel dividescreen = new JPanel( new BorderLayout());















JPanel newuser = new JPanel( new FlowLayout(20, 20, 12));















JPanel userlist = new JPanel( new FlowLayout(20, 20, 12));















JPanel quit = new JPanel( new FlowLayout(20, 20, 12));















JTextArea data = new JTextArea("Registered Users\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6 \n7\n8\n9\n0\n", 3, 40);















JScrollPane newUseruserPane = new JScrollPane( data );















JButton submit = new JButton("SUBMIT");















/**















* @param args















*/















public Example()















{















super ("TabbeLayout Demo");















setBounds(250, 250, 800, 300);
















JPanel newuserfullname = new JPanel( new GridLayout(1, 3));















newuserfullname.add(new JLabel(" Full Name"));















newuserfullname.add(new JLabel(" "));















newuserfullname.add(new JTextField(" ", 10));
















JPanel newusername = new JPanel( new GridLayout(1, 0));















newusername.add(new JLabel(" Logon Name"));















newusername.add(new JLabel(" "));















newusername.add(new JTextField(" ", 10));
















JPanel newuserpword = new JPanel(new GridLayout(1, 0));















newuserpword.add(new JLabel(" Password"));















newuserpword.add(new JLabel(" "));















newuserpword.add(new JTextField(" ", 10));
















submit.setPreferredSize(new Dimension(10, 10));
















newuser.add(newuserfullname);















newuser.add(newusername);















newuser.add(newuserpword);















newuser.add( submit);
















//----------------------------
















dividescreen.add(newuser,"West");















dividescreen.add(newUseruserPane, "Center");
















tabbedPane.addTab( "NewUser", dividescreen);















tabbedPane.addTab( "Quit", quit);
















Container pane = getContentPane();















pane.add(tabbedPane, BorderLayout.CENTER);















setVisible(true);















}
















public static void main(String[] args) {
















Example demo = new Example();















demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );















}
















}































No comments:

Post a Comment