• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make a neat form...

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there does anyone know how to make a form. I need a form with the headings on the lesft handside of the JFrame-
First Name , Last Name , Age
and on the left hand side I need 3 textfields to put the information into.
I tried using a JTable but that did not work... the code I tried is below
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
class AvinTable
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Table of Buttons and TextFields");
JPanel pane = new JPanel();
JTextField field1 = new JTextField("",20);
JTextField field2 = new JTextField("",20);
JButton button = new JButton("Click Me");
Object[][] data ={{button , field1},
{"Enter Number of Call Setups" , field2} };

String[] columnNames ={"Description","Value"};
final JTable table = new JTable(data,columnNames);

JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
pane.add(table);
frame.getContentPane().add(pane);

frame.getContentPane().add(pane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.pack();
frame.setVisible(true) ;
}
}
This did not worked as I expected it. I looks to much like excel. Instead I would like it to look just like how this Java Forum looks when you are posting a message. You will see "Your UserNAme , Your Password and Messssage title. Cam someone tell how to get it to look this neat.
Thanks
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to work with LayoutManagers, or perhaps
the javax.swing.text and javax.swing.text.html
packages.
HTH,
Joe
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can try using a setLayout(null) for the panel and then use setBounds(int xposition, int yposition, int width, int height) method on each of the components to position them
hope this is what u r lookin for
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Using an IDE such as VAJ or JBuilder
2) Using GridBagLayout and your experiences
Most people use the first method, which is easier and work for most purposes. I use the second, because when I started coding in Java, there was no good IDE which could do my job. As a good side effect, I became very very efficient on GridBagLayout.
reply
    Bookmark Topic Watch Topic
  • New Topic