help automate popup code

i have popup codes like this (too many around 12-20 popup screens) painted for demo.

most of them have a kind of 1-2 layout ie

the fields come dynamically from a resultset

i am guessing i can change the SQL code so that i can get the proper field names

eg

SELECT

FIELD1 AS DisplayName1,

FIELD2 AD DisplayName2

...

is there a way to dynamically adjust the layout to set the fields in a good way according to the recordset returned.

--

|Label1:Field1|

|Label1:Field1|

|Label1:Field1|

|Label1:Field1|

|OKCancel|

--

package com.samples.swingsamples;

import javax.swing.*;

import javax.swing.border.*;

import java.awt.*;

import java.awt.event.*;

publicclass clsClaimsEDIextends JDialog

{

public clsClaimsEDI( JFrame frame ){

super( frame,true );

setTitle("EDI Information" );

setSize( 500, 300 );

// Creates a panel to hold all components

JPanel panel =new JPanel(new BorderLayout() );

panel.setLayout(new GridBagLayout() );

// give the panel a border gap of 5 pixels

panel.setBorder(new EmptyBorder(new Insets( 5, 5, 5, 5 ) ) );

getContentPane().add( BorderLayout.NORTH, panel );

GridBagConstraints c =new GridBagConstraints();

// Define preferred sizes for input fields

Dimension shortField =new Dimension( 40, 20 );

Dimension mediumField =new Dimension( 120, 20 );

Dimension longField =new Dimension( 240, 20 );

Dimension hugeField =new Dimension( 240, 80 );

// Spacing between label and field

EmptyBorder border =new EmptyBorder(new Insets( 0, 0, 0, 10 ) );

EmptyBorder border1 =new EmptyBorder(new Insets( 0, 20, 0, 10 ) );

// add space around all components to avoid clutter

c.insets =new Insets( 2, 2, 2, 2 );

// anchor all components WEST

c.anchor = GridBagConstraints.WEST;

JLabel lbl1 =new JLabel("Claim ID" );

lbl1.setBorder( border );// add some space to the right

panel.add( lbl1, c );

JTextField txt1 =new JTextField();

txt1.setPreferredSize( longField );

c.gridx = 1;

c.weightx = 1.0;// use all available horizontal space

c.gridwidth = 3;// spans across 3 columns

c.fill = GridBagConstraints.HORIZONTAL;// fills the 3 columns

panel.add( txt1, c );

JLabel lbl2 =new JLabel("External Reference Number" );

lbl2.setBorder( border );

c.gridwidth = 1;

c.gridx = 0;

c.gridy = 1;;

c.weightx = 0.0;// do not use any extra horizontal space

panel.add( lbl2, c );

JTextField txt2 =new JTextField();

txt2.setPreferredSize( mediumField );

c.gridx = 1;

c.ipadx = 0;// reset the padding to 0

c.ipady = 0;

c.weightx = 1.0;// use all available horizontal space

//c.weighty = 1.0; // use all available vertical space

c.gridwidth = 3;// span across 3 columns

//c.gridheight = 1; // span across 2 rows

c.fill = GridBagConstraints.HORIZONTAL;// fills the cols & rows

panel.add( txt2, c );

JLabel lbl3 =new JLabel("Trading Partner" );

lbl3.setBorder( border );

c.gridx = 0;

c.gridy = 3;

c.gridwidth = 1;

c.gridheight = 1;

c.weightx = 0.0;

c.weighty = 0.0;

c.fill = GridBagConstraints.NONE;

panel.add( lbl3, c );

JTextField txt3 =new JTextField();

txt3.setPreferredSize( mediumField);

c.gridx = 1;

c.gridwidth = 3;// span across 3 columns

c.gridheight = 1;// span across 2 rows

c.fill = GridBagConstraints.BOTH;// fills the cols & rows

panel.add( txt3, c );

c.gridx = 2;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 3;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 0;

c.gridy = 4;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 1;

c.gridwidth = 3;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 0;

c.gridy = 5;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 1;

c.gridwidth = 3;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 0;

c.gridy = 6;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 1;

c.gridwidth = 3;

panel.add( Box.createVerticalStrut(1), c);

c.gridx = 0;

c.gridy = 7;

c.gridwidth = 1;

panel.add( Box.createVerticalStrut(1), c );

c.gridx = 1;

c.gridwidth = 3;

panel.add( Box.createVerticalStrut(1), c );

JButton submitBtn =new JButton("Close" );

c.gridx = 4;

c.gridy = 0;

c.gridwidth = 1;

c.fill = GridBagConstraints.HORIZONTAL;

panel.add( submitBtn, c );

JButton cancelBtn =new JButton("Help" );

c.gridx = 4;

c.gridy = 0;

c.gridwidth = 1;

c.fill = GridBagConstraints.HORIZONTAL;

panel.add( cancelBtn, c );

JButton helpBtn =new JButton("Help" );

c.gridy = 1;

c.anchor = GridBagConstraints.NORTH;// anchor north

panel.add( helpBtn, c );

setVisible(true );

}

}

[7330 byte] By [ootyboya] at [2007-9-29 16:34:36]
# 1
any other popup samples :))
ootyboya at 2007-7-15 14:56:57 > top of Java-index,Archived Forums,New To Java Technology Archive...