Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 10:02 PM
Member
 
Join Date: Dec 2007
Posts: 18
hemanthjava is on a distinguished road
Gridbag Layout Probelm
Hi,
I am a student and have to submit a Mail Program. I have been asked to do the program using GridBagLayout. The program is working fine but for the Layout. I just am not able to manage the layout problems I am facing in this program. Could I get some help to set this right. I don't want to use any other layout. But I just don't believe how weired Layout Problems could get.

I know where the problem lies. Its with the weights Assigned to the components. I just can't am not able to solve this problem. I am facing this alignment issue when I try to resize my Window.

http://www.beginner-java-tutorial.com/Mail.zip
Attached Files
File Type: zip Mail.zip (12.6 KB, 2 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-04-2007, 02:42 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
I know where the problem lies. Its with the weights Assigned to the components. I just can't am not able to solve this problem. I am facing this alignment issue when I try to resize my Window.
I have run your application and see the dialog with components displayed. I can drag the edges of the dialog to resize it and I see what is happening. I do not know how you want things to behave other than what I see. Can you please describe in detail what you want for the behavior of the layout. How must it behave differently to what it does now?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-04-2007, 03:46 AM
Member
 
Join Date: Dec 2007
Posts: 18
hemanthjava is on a distinguished road
Hi,

See, basically I used GrdiBag since it was as per the requirement. Secondly what I am looking for is when I resize the dialog I want even the components to resize (become smaller or larger) when the dialog is resized (smaller or larger) with the relative proportional sizes maintained. What is happening now is all the components get centered and the whole layout gets disturbed. When I resize I don't want the tool bar to float down, but stay where it is.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-04-2007, 07:12 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import java.io.File; import java.util.HashMap; import javax.swing.*; public class InvokerRx { public static void main(String[] args) { String windows = "com.sun.java.swing" + ".plaf.windows.WindowsLookAndFeel"; try { UIManager.setLookAndFeel(windows); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } new MailClientRx(null, "Mail Client", true); } } class MailClientRx extends JDialog { private JPanel mailPanel = null; private JTextArea jtaMessage = null; private JButton jbtSend = null; private JButton jbtCancel = null; private JButton jbtAttachment = null; private JLabel jlbTo = null; private JLabel jlbCc = null; private JLabel jlbBcc = null; private JLabel jlbSubject = null; private JList jlstAttachedFiles = null; private JScrollPane jlstAttachedFilesPane = null; private JTextField jtfTo = null; private JTextField jtfCc = null; private JTextField jtfBcc = null; private JTextField jtfSubject = null; private JFileChooser jfcOpenChooser = null; private JMenuBar jmenubar = null; private JMenu jmenuFile = null; private JMenu jmenuHelp = null; private JMenu jmenuEdit = null; private JMenuItem jmenuitemNew = null; private JMenuItem jmenuitemCut = null; private JMenuItem jmenuitemCopy = null; private JMenuItem jmenuitemPaste = null; private JMenuItem jmenuitemAttachments = null; private JMenuItem jmenuitemHelp = null; private JMenuItem jmenuitemExit = null; private JButton jbtCut = null; private JButton jbtCopy = null; private JButton jbtPaste = null; private JButton jbtHelp = null; private JButton jbtAttachmentsTb = null; private JToolBar jtoolbar = null; private ImageIcon cutIcon = null; private ImageIcon copyIcon = null; private ImageIcon helpIcon = null; private ImageIcon pasteIcon = null; private ImageIcon attachmentsIcon = null; JScrollPane mailMessage; public MailClientRx(Frame frame, String title, boolean modal) { super(frame, title, modal); initComponents(); layoutComponents(); } public MailClientRx() { this((Frame)null, "", false); } private void initComponents(){ JFrame.setDefaultLookAndFeelDecorated(true); this.setSize(400, 400); jlbTo = new JLabel("To"); jlbCc = new JLabel("CC"); jlbBcc = new JLabel("BCC"); jlbSubject = new JLabel("Subject"); jlstAttachedFiles = new JList(); jlstAttachedFilesPane = new JScrollPane(jlstAttachedFiles); jlstAttachedFilesPane.setPreferredSize(new Dimension(150, 75)); jbtAttachment = new JButton("Attachments"); jbtSend = new JButton("Send"); jbtCancel = new JButton("Cancel"); jtfTo = new JTextField() ; jtfCc = new JTextField(); jtfBcc = new JTextField(); jtfSubject = new JTextField(); jtaMessage = new JTextArea(); jtaMessage.setPreferredSize(new java.awt.Dimension(300, 200)); jtaMessage.setMinimumSize(new java.awt.Dimension(100, 50)); /*JScrollPane*/ mailMessage = new JScrollPane(jtaMessage); jtaMessage.setLineWrap(true); jfcOpenChooser = new JFileChooser(); jtoolbar = new JToolBar(); cutIcon = new ImageIcon("cut.jpg"); copyIcon = new ImageIcon("copy.jpg"); helpIcon = new ImageIcon("help.gif"); pasteIcon = new ImageIcon("paste.jpg"); attachmentsIcon = new ImageIcon("attachments.jpg"); jmenubar = new JMenuBar(); jmenuFile = new JMenu("File"); jmenuHelp = new JMenu("Help"); jmenuEdit = new JMenu("Edit"); jmenuitemNew = new JMenuItem("New Mail"); jmenuitemCut = new JMenuItem("Cut", cutIcon); jmenuitemCopy = new JMenuItem("Copy", copyIcon); jmenuitemPaste = new JMenuItem("Paste", pasteIcon); jmenuitemAttachments = new JMenuItem("Attachments", attachmentsIcon); jmenuitemHelp = new JMenuItem("Help", helpIcon); jmenuitemExit = new JMenuItem("Exit"); jbtCut = new JButton(cutIcon); jbtCopy = new JButton(copyIcon); jbtPaste = new JButton(pasteIcon); jbtHelp = new JButton(helpIcon); jbtAttachmentsTb = new JButton(attachmentsIcon); jbtCut.setToolTipText("Cut"); jbtCopy.setToolTipText("Copy"); jbtPaste.setToolTipText("Paste"); jbtHelp.setToolTipText("Help"); jbtAttachmentsTb.setToolTipText("Attachment"); jmenuFile.add(jmenuitemNew); jmenuFile.add(jmenuitemCut); jmenuEdit.add(jmenuitemCopy); jmenuEdit.add(jmenuitemPaste); jmenuEdit.add(jmenuitemAttachments); jmenuHelp.add(jmenuitemHelp); jmenuHelp.add(jmenuitemExit); jmenubar.add(jmenuFile); jmenubar.add(jmenuEdit); jmenubar.add(jmenuHelp); jtoolbar.add(jbtCut); jtoolbar.add(jbtCopy); jtoolbar.add(jbtPaste); jtoolbar.add(jbtHelp); jtoolbar.add(jbtAttachmentsTb); jbtSend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jbtOK_actionPerformed(e); } }); jbtCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jbtCancel_actionPerformed(e); } }); jbtAttachment.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jbtAttachment_actionPerformed(e); } }); } private void layoutComponents() { this.setLayout(new GridBagLayout()); GridBagConstraints toolbarCons = new GridBagConstraints(); toolbarCons = new GridBagConstraints(0,0,1,1,0.1,0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel = new JPanel(); mailPanel.setLayout(new GridBagLayout()); GridBagConstraints cons = new GridBagConstraints(); cons = new GridBagConstraints(0,0,1,1,0,1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jlbTo, cons); cons = new GridBagConstraints(1,0,4,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel.add(jtfTo, cons); cons = new GridBagConstraints(0,1,1,1,0,1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jlbCc, cons); cons = new GridBagConstraints(1,1,4,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel.add(jtfCc, cons); cons = new GridBagConstraints(0,2,1,1,0,1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jlbBcc, cons); cons = new GridBagConstraints(1,2,4,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel.add(jtfBcc, cons); cons = new GridBagConstraints(0,3,1,1,0,1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jlbSubject, cons); cons = new GridBagConstraints(1,3,4,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel.add(jtfSubject, cons); cons = new GridBagConstraints(0,4,1,1,0,1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jbtAttachment, cons); cons = new GridBagConstraints(1,4,1,1,1.0,1.0, // 4 col GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jlstAttachedFilesPane, cons); cons = new GridBagConstraints(1,5,1,1,1.0,1.0, // 4c 4r GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); mailPanel.add(mailMessage, cons); cons = new GridBagConstraints(0,9,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jbtSend, cons); cons = new GridBagConstraints(1,9,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0); mailPanel.add(jbtCancel, cons); // this.getContentPane().add(mailPanel, toolbarCons); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setJMenuBar(jmenubar); jtoolbar.setFloatable(false); this.getContentPane().add(jtoolbar, toolbarCons); GridBagConstraints mainPanelCons = new GridBagConstraints(); mainPanelCons = new GridBagConstraints(0,1,1,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5,5,0,5),0,0); this.getContentPane().add(mailPanel, mainPanelCons); this.pack(); this.setVisible(true); } private void jbtOK_actionPerformed(ActionEvent e) { // Business Logic this.dispose(); } private void jbtCancel_actionPerformed(ActionEvent e) { this.dispose(); } private void jbtAttachment_actionPerformed(ActionEvent e) { jfcOpenChooser.setMultiSelectionEnabled(true); jfcOpenChooser.showOpenDialog(null); File[] fileArray = jfcOpenChooser.getSelectedFiles(); String[] fileNames = new String[fileArray.length]; for(int i=0; i < fileArray.length; i++){ File file = fileArray[i]; fileNames[i] = file.getPath().trim(); // fileNames[i] = file.getName().trim(); } jlstAttachedFiles.setListData(fileNames); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JTree Programmatic Node Expansion and Selection Probelm hemanthjava AWT / Swing 1 01-17-2008 08:36 AM
SWT Layout JavaForums Java Blogs 0 12-31-2007 06:53 PM
Layout Managers gmioannou AWT / Swing 1 12-24-2007 06:12 AM
Dom4j probelm with clearContent method aorteu New To Java 0 11-23-2007 05:36 PM
MiG Layout Manager 2.4 levent Java Announcements 0 05-16-2007 07:11 AM


All times are GMT +3. The time now is 03:23 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org