Swing UI alignment Issue on different Platform
View Answers
October 13, 2008 at 12:41 PM
October 14, 2008 at 1:01 PM
Hi Sekhar,
This is modified code.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class SampleReport implements ActionListener {
Class[] columnClasses = null;
JTable AssociateStationTable = null;
private Object dataValues[][];
private String columnNames[] = { "Name ", "Address ", "State ", "ID ",
"Dept. Name", " Mode ", "Status ", "Power " };
public SampleReport() {
JPanel btnPanel = new JPanel();
JButton refreshBtn = new JButton("Refresh");
JButton print = new JButton("Print");
JButton startPoll = new JButton("Poll");
JButton showTdata = new JButton("Send Data");
JButton olddata = new JButton("Copy Data");
JButton expdata = new JButton("Export Data");
JButton createnewrpt = new JButton("Create Reprort");
JButton showRdata = new JButton("Receive Data");
JButton radiostat = new JButton("Statistics");
JButton CloseBtn = new JButton("Close");
btnPanel.add(refreshBtn);
btnPanel.add(print);
btnPanel.add(startPoll);
btnPanel.add(olddata);
btnPanel.add(expdata);
btnPanel.add(createnewrpt);
btnPanel.add(showTdata);
btnPanel.add(showRdata);
btnPanel.add(CloseBtn);
JFrame frame = new JFrame("Sample Report UI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
JPanel mainpanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 10);
mainpanel.add(getUI(), c);
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 10);
mainpanel.add(getSchedulePanel(), c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(0, 0, 0, 0);
mainpanel.add(btnPanel, c);
frame.add(mainpanel);
frame.setSize(855, 500);
frame.setVisible(true);
}
October 14, 2008 at 1:03 PM
public JPanel getUI() {
JPanel tablePanel = new JPanel();
tablePanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
TableModel model = new DefaultTableModel(dataValues, columnNames) {
public Class getColumnClass(int column) {
Class returnValue;
if ((column >= 0) && (column < getColumnCount())) {
returnValue = columnClasses[column];
} else {
returnValue = Object.class;
}
return returnValue;
}
};
JTable AssociateStationTable = new JTable(model);
AssociateStationTable.getTableHeader().setPreferredSize(
new Dimension(0, 40));
JScrollPane tableScroll = new JScrollPane(AssociateStationTable);
tableScroll.setMinimumSize(new Dimension(800, 300));
tableScroll
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableScroll
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
tableScroll.setPreferredSize(new Dimension(800, 300));
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 1.0;
c.weighty = 1.0;
c.insets = new Insets(0, 0, 0, 0);
c.fill = GridBagConstraints.BOTH;
tablePanel.add(tableScroll, c);
return tablePanel;
}
public void actionPerformed(ActionEvent e) {
}
private JPanel getSchedulePanel() {
JPanel schedulePanel = new JPanel(new GridBagLayout());
schedulePanel.setPreferredSize(new Dimension(800, 80));
schedulePanel.setBorder(new TitledBorder("Input Parameters"));
JLabel pollLabel = new JLabel("Refresh Data");
JLabel exportLabel = new JLabel("Send Report");
JLabel appendLabel = new JLabel("Append Report");
JLabel pollSeconds = new JLabel("Sec");
JTextField pollIntervalField = new JTextField();
pollIntervalField.setMinimumSize(new Dimension(25, 25));
pollIntervalField.setColumns(5);
JCheckBox exportCheckBox = new JCheckBox();
JCheckBox appendDataCheckBox = new JCheckBox();
appendDataCheckBox.setEnabled(true);
JLabel fileLabel = new JLabel("Output File");
JButton chooserComponent = new JButton("Search");
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(pollLabel, c);
October 14, 2008 at 1:04 PM
c.gridx = 1;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 0);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(pollIntervalField, c);
c.gridx = 2;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 0, 10, 10);
schedulePanel.add(pollSeconds, c);
c.gridx = 6;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 0);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(exportCheckBox, c);
c.gridx = 7;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 0, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(exportLabel, c);
c.gridx = 8;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(fileLabel, c);
c.gridx = 9;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(chooserComponent, c);
c.gridx = 10;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 10, 10, 0);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(appendDataCheckBox, c);
c.gridx = 11;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 1.0;
c.insets = new Insets(10, 0, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
schedulePanel.add(appendLabel, c);
return schedulePanel;
}
public static void main(String[] args) throws Exception {
new SampleReport();
}
}
----------------------------
Thanks & Regards
October 14, 2008 at 2:22 PM
Hi friend,
Thanks for your reply.
I don't see any change in the modified code which you have posted .
Pls. can you check it once.
Regards
Shekhar
October 14, 2008 at 6:48 PM
Hi,
what's your problem? please explain in detail.
Thanks.
October 15, 2008 at 11:39 AM
Hi,
We are developing UI using Java Swing on windows, As java is a platform independent , I expected LAF will be same on all the platforms (i.e. windows and Unix).
But when I execute the posted source code in Linux the LAF is getting changed (i.e. some of the buttons are not displaying on the UI and panel alignment is also getting changed) compare to windows LAF .
Please can you look in to this.
Regards
shekhar
Related Tutorials/Questions & Answers:
Advertisements
Cross Platform issue - Java BeginnersCross
Platform issue Basically,this is a follow up to the last question.
I have the alert so that the key pressed will be displayed in a firefox browser. How do I get it from an alert to be displayed in a textbox like
Query on Java Swing - Table Cell Issue - Swing AWTQuery on Java
Swing - Table Cell Issue Hi,
I have a query on Java
Swing.
we are using
swing in our application, In one of the frame we are using JTable which has 6 columns which are editable.
When I use the TAB button from
Tooltip alignment alignment of that tooltip as desired.The Div is seen in the other position other than
Tooltip Alignment alignment of that tooltip as desired.The Div is seen in the other position other than
ModuleNotFoundError: No module named 'alignment'ModuleNotFoundError: No module named '
alignment' Hi,
My Python... '
alignment'
How to remove the ModuleNotFoundError: No module named '
alignment' error?
Thanks
Hi,
In your python environment you
alignment for header and footeralignment for header and footer header and footer
alignment is not fit like footer is not fit in bottom some white space is there in jsf, what to do
SWINGSWING A JAVA CODE OF MOVING TRAIN IN
SWING Alignment in struts 2.0 - StrutsAlignment in struts 2.0 Hi, I am working in Struts 2.0. I have 2 queries. 1) I have used tr and td but i am not able to align in center. 2)label and textfield are not coming in same line. indentation is not proper
swingswing Write a java
swing program to delete a selected record from a table
swingswing How to make
swing component auto-resizable when JFrame resize
Alignment of Image in HTML;align> is used to define the
alignment of
the image. This define the
different position of image in the HTML page. The
alignment of images define
different location...
Alignment of Image in HTML
SwingSwing Write a java
swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed