File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
How to set paddings?
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 484
I like...
posted
Sep 06, 2011 11:21:11
0
Hi,
Please have a look at the following code
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class EmployeeInfo extends JFrame { JLabel nameLabel, ageLabel, addressLabel; JTextField nameTxt, ageTxt; JTextArea addressTxt; JScrollPane scroll; JPanel scrollPanel; JButton insert, clear; public EmployeeInfo() { //Decalring Variables// nameLabel = new JLabel("Name"); ageLabel = new JLabel("Age"); addressLabel = new JLabel("Address"); nameTxt = new JTextField(10); ageTxt = new JTextField(10); addressTxt = new JTextArea(2,25); insert = new JButton("Insert"); clear = new JButton("Clear"); scroll = new JScrollPane(addressTxt); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPanel = new JPanel(); //Setting up JTextArea// addressTxt.setLineWrap(true); scrollPanel.add(scroll); //Setting up the display// JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(3,2)); centerPanel.add(nameLabel); centerPanel.add(nameTxt); centerPanel.add(ageLabel); centerPanel.add(ageTxt); centerPanel.add(addressLabel); centerPanel.add(scrollPanel); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); buttonPanel.add(insert); buttonPanel.add(clear); JPanel southPanel = new JPanel(); southPanel.setLayout(new FlowLayout()); southPanel.add(buttonPanel); getContentPane().add(centerPanel,"Center"); getContentPane().add(southPanel,"South"); this.setResizable(false); this.setTitle("Employee Information"); } public static void main(String[]args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { JOptionPane.showMessageDialog(null,"GUI Error: "+e); } EmployeeInfo e = new EmployeeInfo(); e.setSize(450,200); e.setVisible(true); e.validate(); e.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
I want to have some vertical space between the text fields. How could I do that? Please help...
Are you better than me? Then please show me my mistakes..
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8430
I like...
posted
Sep 06, 2011 11:41:48
0
Check out
GridLayout
API docs for a constructor which lets you define the gaps
[
Donate a pint, save a life!
] [
How to ask questions
] [
Onff-turn it on!
]
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 484
I like...
posted
Sep 06, 2011 11:51:55
0
Maneesh Godbole wrote:
Check out
GridLayout
API docs for a constructor which lets you define the gaps
Thanks a lot for the quick reply.. I will check it and come back :
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 484
I like...
posted
Sep 10, 2011 01:13:40
0
First, pardon me for the late reply...
Thanks lot for the answer... It worked...
I agree. Here's the link:
http://aspose.com/file-tools
subject: How to set paddings?
Similar Threads
Java uses or overrides a deprecated API?
Maximize button in JDialog
Alignment Issue
RMI: FileNotFound exception and NullPointException
The "Next" is not working
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter