import net.java.dev.designgridlayout.Tag;
import net.java.dev.designgridlayout.DesignGridLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
class alignmentprob
{
JFrame JF;
Container C,C5;
JDesktopPane JDP;
JInternalFrame JIF5;
JLabel i5l1,i5l2,i5l3,i5l4,i5l5,i5l6,i5l7;
JTextField i5t1,i5t2,i5t3;
JComboBox<String> i5cb1;
JButton i5b1,i5b2,i5b3;
JSeparator i5sep1,i5sep2,i5sep3,i5sep4,i5sep5,i5sep6;
JTable i5Table1;
DefaultTableModel i5Model;
String[] i5Credit = {"A","B"};
String[] i5ColumnNames = {"Name","Qty","Rate/kg","rate/dzn","total amt."};
JScrollPane i5t1sp1;
public alignmentprob()
{
JF = new JFrame();
JDP = new JDesktopPane();
JF.setVisible(true);
JF.setSize(800,600);
JIF5 = new JInternalFrame("Daily Analysis",true,true, true, true);
C=JF.getContentPane();
C.add(JDP,BorderLayout.CENTER);
JIF5.setVisible(true);
JIF5.setBounds(10, 10, 600, 500);
C5 = JIF5.getContentPane();
DesignGridLayout layout5 = new DesignGridLayout(C5);
i5l1 = new JLabel("FREIGHT DETAILS");
i5l2 = new JLabel("Date : ");
i5l3 = new JLabel("SALE DETAILS");
i5l4 = new JLabel("Cash Sales : Rs. ");
i5l5 = new JLabel("Credit : ");
i5l6 = new JLabel("EXPENSES");
i5l7 = new JLabel("Food & Tea : Rs. ");
i5t1 = new JTextField(20);
i5t2 = new JTextField(20);
i5t3 = new JTextField(20);
i5cb1 = new JComboBox<String>(i5Credit);
i5b1 = new JButton("Save");
i5b2 = new JButton("Reset");
i5b3 = new JButton("Close");
i5sep1 = new JSeparator();
i5sep2 = new JSeparator();
i5sep3 = new JSeparator();
i5sep4 = new JSeparator();
i5sep5 = new JSeparator();
i5sep6 = new JSeparator();
i5Model = new DefaultTableModel(i5ColumnNames,5);
i5Table1 =new JTable(i5Model){@Override
public boolean isCellEditable(int arg0, int arg1)
{
return false;
}
};
i5t1sp1 = new JScrollPane(i5Table1);
layout5.row().left().add(i5sep1).fill().withOwnRowWidth();
layout5.row().center().add(i5l1);
layout5.row().left().add(i5sep2).fill().withOwnRowWidth();
layout5.row().grid(i5l2).add(i5t1);
layout5.row().left().add(i5sep3).fill().withOwnRowWidth();
layout5.row().center().add(i5l3);
layout5.row().left().add(i5sep4).fill().withOwnRowWidth();
layout5.row().grid(i5l4).add(i5t2);
layout5.row().grid(i5l5).add(i5cb1);
layout5.row().left().add(i5t1sp1);
layout5.row().left().add(i5sep5).fill().withOwnRowWidth();
layout5.row().center().add(i5l6);
layout5.row().left().add(i5sep6).fill().withOwnRowWidth();
layout5.row().grid(i5l7).add(i5t3);
layout5.row().center().add(i5b1).add(i5b2).add(i5b3);
JDP.add(JIF5);
}
public static void main(String args[])
{
new alignmentprob();
}
}
My problem is that the textfields are too long and go out of bounds. The table I made consists of 5 rows, but it tends to take up more space. I actually wanted to align the FREIGHT DETAILS & SALES DETAILS in parallel, separated using a vertical line. Please help me with code to do all this, so that my form looks neat and is fully visible.
I wasn't able to reproduce the issue based on the code you've posted. Maybe there's something else I'm not seeing that causes this behaviour.
Even when working with third-party layout managers such as DesignGridLayout you can follow a Nested Layout approach using
JPanel
's to group Freight details and Sales detail components.About the vertical separator, don't think it's possible with DesignGridLayout. While you can have components spanning several rows it doesn't work with
JSeparator
.StackOverflow is not a code factory so in most cases people won't do your job for you but they can provide useful examples. However as I've had to copy all your code to test it and I've made some changes using nested layouts approach, I'll make an exception here. Hope it be helpful:
Screenshot