Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Regarding JTextfield and Jlabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Regarding JTextfield and Jlabel" Watch "Regarding JTextfield and Jlabel" New topic
Author

Regarding JTextfield and Jlabel

Krunal Naik
Greenhorn

Joined: Mar 14, 2010
Posts: 7
I am making application which has JLabel and Jtextfield for that.

I already setup code for JCombobox and Jtextaread also set the layout .

when i add the Jlabel and Jtextfield it will not show up.

here it is the code which combines JLabel and JTextfield.

JTextArea textareaMethodnames;
JTextArea textareaMethodnames1;
JTextArea textareaMethodnames2;
JTextField jf1;
JTextField jf2;
JTextField jf3;
JTextField jf4;
JLabel j1;
JLabel j2;
JLabel j3;
JLabel j4;
JList list1;
ListSelectionModel listSelectionModel;
JScrollPane listsc;
Container cp;
DefaultListModel dp;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
Vector<String> c = new Vector<String>();
static JComboBox cb;
private final static String newline = "\n";

JComboBox petList = new JComboBox(petStrings);

petList.addActionListener(this);

listsc = new JScrollPane(list1);
listsc.setPreferredSize(new Dimension(100,100));
listsc.setAlignmentX(LEFT_ALIGNMENT);
dp = new DefaultListModel();

jf1= new JTextField(50);
jf1.addActionListener(this);

jf2 =new JTextField(50);
jf2.addActionListener(this);


jf3= new JTextField(50);
jf3.addActionListener(this);


jf4 =new JTextField(50);
jf4.addActionListener(this);



ImageIcon icon = createImageIcon("c:/webservice.gif", "Web Service");


j1 = new JLabel("Assert input for Web Sevice");
j1.setVerticalTextPosition(JLabel.BOTTOM);
j1.setHorizontalTextPosition(JLabel.CENTER);


j2 = new JLabel("Assert output for Web Service");
j2= new JLabel("Text-Only Label");



j3= new JLabel(" Extended Input for Web Service");
j3 = new JLabel(icon);
j4 = new JLabel(" Extended output for Web Service");
j4 = new JLabel(icon);

jf1.setLocation(24,50 );


textareaMethodnames = new JTextArea();
textareaMethodnames.setFont(textareaMethodnames.getFont().deriveFont(Font.ITALIC));
updateLabel(petStrings[petList.getSelectedIndex()]);
textareaMethodnames.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));

textareaMethodnames1 = new JTextArea();
textareaMethodnames1.setFont(textareaMethodnames.getFont().deriveFont(Font.ITALIC));
updateLabel(petStrings[petList.getSelectedIndex()]);
textareaMethodnames1.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));

textareaMethodnames2 = new JTextArea();
textareaMethodnames2.setFont(textareaMethodnames.getFont().deriveFont(Font.ITALIC));
updateLabel(petStrings[petList.getSelectedIndex()]);
textareaMethodnames2.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
// updateLabel(petStrings[petList.getSelectedIndex()]);
// textareaMethodnames.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));

//The preferred size is hard-coded to be the width of the
//widest image and the height of the tallest image + the border.
//A real program would compute this.

textareaMethodnames.setPreferredSize(new Dimension(98,117));
textareaMethodnames1.setPreferredSize(new Dimension(117,59));
textareaMethodnames2.setPreferredSize(new Dimension(117,107));




//Lay out the demo.
add(petList, BorderLayout.PAGE_START);
add(textareaMethodnames, BorderLayout.PAGE_END);
add(textareaMethodnames2,BorderLayout.EAST);
add(textareaMethodnames1,BorderLayout.WEST);
add(j1);
add(j2);
add(j3);
add(j4);
add(jf1);
add(jf2);
add(jf3);
add(jf4);

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Read up in the tutorials on how to use layouts as you are not using them correctly. Also, check the FAQ about code tags. Much luck!
Krunal Naik
Greenhorn

Joined: Mar 14, 2010
Posts: 7
for this kind of project which kind of layout i have to use.
can you please help?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
The tutorial will show you a visual representation of the major layouts, and often you will use a combination of layouts by nesting JPanels that each use a different layout. Experiment. Play with them. Have fun with them.
Krunal Naik
Greenhorn

Joined: Mar 14, 2010
Posts: 7
I used BorderLayout for JComboBox and TextArea.

I want to use GridBagLayout for JLabel and JTextField.

how can i use it ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You can use multiple layout managers by grouping components together in JPanels, then adding these to the main container (frame, dialog). Your example would need two JPanels for grouping.

And as Pete mentioned, please UseCodeTags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Regarding JTextfield and Jlabel
 
Similar Threads
Adding components dynamically to a nested JPanel
Accessing image files in an applet
Need help with Layout
Different Cursors
jframe not accepting sql query..