trying to use designer

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

trying to use designer

Postby Helloworld » Wed Feb 08, 2006 9:56 am

I know I made a mistake somewhere. Not sure which option I didn't checkoff. I tried the Client Billing Example and try to modify for my own use, but seems to have problem of "GridBagLayout" shift when a button is clicked.

when click on the Quick1 button you will notice the tabbpanel shift to the left, why?!! Maybe people who use Swing Designer can see it more clearly. thx

Code: Select all
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeListener;

public class SignatureJ{

   private SpringLayout springLayout_2;
   private SpringLayout springLayout_1;
   private JPanel panel_1;
   private JTextField txSearch;
   private SpringLayout springLayout;
   private JFrame frame;
    private JTabbedPane tabbedPane;
   /**
    * Launch the application
    * @param args
    */
   public static void main(String args[]) {
      try {
         SignatureJ window = new SignatureJ();
         window.frame.setVisible(true);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   /**
    * Create the application
    */
   public SignatureJ() {
      initialize();
   }

   /**
    * Initialize the contents of the frame
    */
   private void initialize() {
      frame = new JFrame();
      frame.getContentPane().setLayout(new GridBagLayout());
      frame.setTitle("Signature Card Browser");
      frame.setBounds(100, 100, 800, 800);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      final JPanel panel = new JPanel();
      springLayout = new SpringLayout();
      panel.setLayout(springLayout);
      final GridBagConstraints gridBagConstraints = new GridBagConstraints();
      gridBagConstraints.insets = new Insets(0, 0, 0, 0);
      gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;
      gridBagConstraints.fill = GridBagConstraints.BOTH;
      gridBagConstraints.weighty = .75;
      gridBagConstraints.weightx = .25;
      gridBagConstraints.gridy = 0;
      gridBagConstraints.gridx = 0;
      frame.getContentPane().add(panel, gridBagConstraints);

      txSearch = new JTextField();
      txSearch.setText("D4801423");
      panel.add(txSearch);
      springLayout.putConstraint(SpringLayout.SOUTH, txSearch, 45, SpringLayout.NORTH, panel);
      springLayout.putConstraint(SpringLayout.NORTH, txSearch, 25, SpringLayout.NORTH, panel);
      springLayout.putConstraint(SpringLayout.EAST, txSearch, -5, SpringLayout.EAST, panel);
      springLayout.putConstraint(SpringLayout.WEST, txSearch, 10, SpringLayout.WEST, panel);

      final JButton quick1Button = new JButton();
      quick1Button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            retrieveQuick1();
         }
      });
      quick1Button.setText("Quick 1");
      panel.add(quick1Button);
      springLayout.putConstraint(SpringLayout.EAST, quick1Button, -5, SpringLayout.EAST, panel);
      springLayout.putConstraint(SpringLayout.SOUTH, quick1Button, 90, SpringLayout.NORTH, panel);
      springLayout.putConstraint(SpringLayout.NORTH, quick1Button, 57, SpringLayout.NORTH, panel);
      springLayout.putConstraint(SpringLayout.WEST, quick1Button, 15, SpringLayout.WEST, panel);

      // setup tab
      tabbedPane = new JTabbedPane();
         
      final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
      gridBagConstraints_1.fill = GridBagConstraints.BOTH;
      gridBagConstraints_1.gridwidth = 1;
      gridBagConstraints_1.gridheight = 2;
      gridBagConstraints_1.weighty = 1;
      gridBagConstraints_1.weightx = .75;
      gridBagConstraints_1.gridy = 0;
      gridBagConstraints_1.gridx = 1;
      frame.getContentPane().add(tabbedPane, gridBagConstraints_1);

      
      JPanel panel_1 = new JPanel();
      tabbedPane.addTab("tab1", null, panel_1, null);
      //tabbedPane.setPreferredSize(new Dimension(600, 300));
      springLayout_2 = new SpringLayout();
      panel_1.setLayout(springLayout_2);
      
      final JPanel LowerLeftPanel = new JPanel();
      springLayout_1 = new SpringLayout();
      LowerLeftPanel.setLayout(springLayout_1);
      LowerLeftPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
      final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
      gridBagConstraints_2.fill = GridBagConstraints.BOTH;
      gridBagConstraints_2.weighty = .25;
      gridBagConstraints_2.weightx = .25;
      gridBagConstraints_2.gridy = 1;
      gridBagConstraints_2.gridx = 0;
      frame.getContentPane().add(LowerLeftPanel, gridBagConstraints_2);

      final JLabel Information = new JLabel();
      LowerLeftPanel.add(Information);
      springLayout_1.putConstraint(SpringLayout.SOUTH, Information, 39, SpringLayout.NORTH, LowerLeftPanel);
      springLayout_1.putConstraint(SpringLayout.EAST, Information, 96, SpringLayout.WEST, LowerLeftPanel);
      springLayout_1.putConstraint(SpringLayout.NORTH, Information, 25, SpringLayout.NORTH, LowerLeftPanel);
      springLayout_1.putConstraint(SpringLayout.WEST, Information, 10, SpringLayout.WEST, LowerLeftPanel);
      Information.setText("Some information");
      //frame.setExtendedState(frame.MAXIMIZED_BOTH);

   }

   
   private void retrieveQuick1(){
      String prefix = txSearch.getText();
      System.out.println(" txSearch = " + prefix);

      DisplaySignaturePanel  fileInfoListPanel = new DisplaySignaturePanel(prefix, "TIF");
      tabbedPane.setComponentAt(0, fileInfoListPanel);
      
      //    tabbedPane.add("SIGNATURE", fileInfoListPanel);      
   }
   
   
   
   
}




Code: Select all
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;


import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SpringLayout;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

import com.ibc.signaturej.DisplaySignature;


//TODO:  this panel is too wide.

public class DisplaySignaturePanel extends JPanel implements
       ActionListener, MouseMotionListener, MouseListener {

   // The instance of DisplayThumbnail.
   private DisplaySignature dt;


   // Two labels to show the world (original image) and thumbnail viewport
   // coordinates.
   private JLabel world, view;


   // just testing move it outside
   private JPanel borderDisplay;

   private Container contentPane;

   private SpringLayout layout;

   private int currentSourceIndex;


   // constructor
   public DisplaySignaturePanel(String prefix, String suffix) {
      
   
      // Create a JPanel
      borderDisplay = new JPanel();
      borderDisplay.setBackground(Color.RED);
      
      final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
      gridBagConstraints_1.gridx = 0;
      gridBagConstraints_1.gridy = 0;
      gridBagConstraints_1.insets = new Insets(16, 83, 156, 0);
      add(borderDisplay, gridBagConstraints_1);
      borderDisplay.setLayout(new GridBagLayout());
      
      borderDisplay.setBorder(BorderFactory
            .createBevelBorder(BevelBorder.RAISED));      

      final JButton button = new JButton();
      button.setMargin(new Insets(0, 0, 0, 0));
      button.setText("New JButton");
      final GridBagConstraints gridBagConstraints = new GridBagConstraints();
      gridBagConstraints.gridy = 0;
      gridBagConstraints.gridx = 0;
      borderDisplay.add(button, gridBagConstraints);
      
      // Navg ===============
      final JPanel navigTop = new JPanel();
      navigTop.setLayout(new BoxLayout(navigTop, BoxLayout.Y_AXIS));
      final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
      gridBagConstraints_2.gridx = 1;
      gridBagConstraints_2.gridy = 0;
      gridBagConstraints_2.insets = new Insets(5, 5, 144, 83);
      add(navigTop, gridBagConstraints_2);

      final JButton previousButton = new JButton();   
      navigTop.add(previousButton);
      previousButton.setText("Previous");
        previousButton.addActionListener(this);
       
      final JButton nextButton = new JButton();
      navigTop.add(nextButton);
      nextButton.setText("Next");
      nextButton.addActionListener(this);            
      // to set default index
      setSize(317, 195);
      setLayout(new GridBagLayout());
      
   }



private void createGUIBrowser(int dWidth, int dHeight){
      
      
   }   
   


   /*
    *
    *
    */
   public void mousePressed(MouseEvent e) {
      debug("===App.mousePressed====");

   }


   public void mouseClicked(MouseEvent e) {

   }

   /**
    * This method will be called when we drag the mouse over the thumbnail.
    *
    */
   public void mouseDragged(MouseEvent e) {

      debug("App.mouseDragged ");

            
   }

   /**
    * This method is here just to keep the MouseMotionListener interface happy.
    */
   public void mouseMoved(MouseEvent e) {
   }


   //
   public void repaint() {

   }

   public void actionPerformed(ActionEvent e) {
      debug("call to actionPerformed : " + e.getActionCommand());


      repaint();
   
    }   
   
   
   /**
    * Test harness
    *
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub

   }

   public void debug(String msg) {
      System.out.println(msg);

   }



   public void mouseReleased(MouseEvent arg0) {
      // TODO Auto-generated method stub
      
   }



   public void mouseEntered(MouseEvent arg0) {
      // TODO Auto-generated method stub
      
   }



   public void mouseExited(MouseEvent arg0) {
      // TODO Auto-generated method stub
      
   }

   


}
Helloworld
 
Posts: 7
Joined: Fri Dec 16, 2005 1:33 pm

Postby Helloworld » Thu Feb 09, 2006 11:10 am

not sure if there are other ways for this issue, but I was told to set perfer size.

cheers,
Helloworld
 
Posts: 7
Joined: Fri Dec 16, 2005 1:33 pm


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest