Swing UI alignment Issue on different Platform

Swing UI alignment Issue on different Platform

View Answers

October 13, 2008 at 12:41 PM

Hi friend,


For more information on Swing visit to :

http://www.roseindia.net/java/example/java/swing/


Thanks

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:
Swing UI alignment Issue on different Platform - Swing AWT
Swing UI alignment Issue on different Platform  Hi, We are developing screens using Java Swing on windows. The problem is when we take the same screen in Linux machine, The alignment is changing. This is happening if we change
Swing UI alignment Issue on different Platform - Swing AWT
Swing UI alignment Issue on different Platform  Hi, We are developing UI using Java Swing on windows. The problem is when we Test the same Ui... are developing UI using Java Swing on windows, As java is a platform independent , I
Advertisements
Cross Platform issue - Java Beginners
Cross 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 AWT
Query 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
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.  Hi, I have a similar question related to HeaderFooter class, I want to display three Phrases
Version of com.thesett>debug_ui_tools_swing dependency
List of Version of com.thesett>debug_ui_tools_swing dependency
Maven Dependency debug_ui_tools_swing >> 0.9.97
You should include the dependency code given in this page to add Maven Dependency of com.thesett >> debug_ui_tools_swing version0.9.97 in your project
Maven Dependency debug_ui_tools_swing >> 0.9.77
You should include the dependency code given in this page to add Maven Dependency of com.thesett >> debug_ui_tools_swing version0.9.77 in your project
Maven Dependency debug_ui_tools_swing >> 0.9.117
You should include the dependency code given in this page to add Maven Dependency of com.thesett >> debug_ui_tools_swing version0.9.117 in your project
Maven Repository/Dependency: com.thesett | debug_ui_tools_swing
Maven Repository/Dependency of Group ID com.thesett and Artifact ID debug_ui_tools_swing. Latest version of com.thesett:debug_ui_tools_swing dependencies. # Version Release Date You can
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for debug_ui_tools_swing version 0.9.117
com.thesett:debug_ui_tools_swing:0.9.117 Java library in your project.. Maven..._ui_tools_swing version 0.9.117. You be able to use the dependency given here for the  debug_ui_tools_swing version 0.9.117 just by copying
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for debug_ui_tools_swing version 0.9.97
com.thesett:debug_ui_tools_swing:0.9.97 Java library in your project.. Maven... for the  debug_ui_tools_swing version 0.9.97 just by copying and pasting... details: Group: com.thesett Artifact: debug_ui_tools_swing ADS_TO_REPLACE_2
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for debug_ui_tools_swing version 0.9.77
com.thesett:debug_ui_tools_swing:0.9.77 Java library in your project.. Maven... for the  debug_ui_tools_swing version 0.9.77 just by copying and pasting... details: Group: com.thesett Artifact: debug_ui_tools_swing ADS_TO_REPLACE_2
Maven Repository/Dependency: org.nuxeo.ecm.platform | nuxeo-platform-ui-web
Maven Repository/Dependency of Group ID org.nuxeo.ecm.platform and Artifact ID nuxeo-platform-ui-web. Latest version of org.nuxeo.ecm.platform:nuxeo-platform-ui-web dependencies. # Version Release Date
Maven Repository/Dependency: org.xwiki.platform | xwiki-platform-administration-ui
Maven Repository/Dependency of Group ID org.xwiki.platform and Artifact ID xwiki-platform-administration-ui. Latest version of org.xwiki.platform:xwiki-platform-administration-ui dependencies. # Version
Maven Repository/Dependency: org.xwiki.platform | xwiki-platform-panels-ui
Maven Repository/Dependency of Group ID org.xwiki.platform and Artifact ID xwiki-platform-panels-ui. Latest version of org.xwiki.platform:xwiki-platform-panels-ui dependencies. # Version Release Date
Maven Repository/Dependency: org.xwiki.platform | xwiki-platform-test-ui
Maven Repository/Dependency of Group ID org.xwiki.platform and Artifact ID xwiki-platform-test-ui. Latest version of org.xwiki.platform:xwiki-platform-test-ui dependencies. # Version Release Date
Java Swing Tutorial - Learning Java Swing programming step by step
Start. But mostly Java Swing is used to develop platform independent desktop... supports platform independence Application design can be customized as Swing API provides room for better customization of UI interfaces Swing
Java Swing Tutorial - Learning Java Swing programming step by step
Start. But mostly Java Swing is used to develop platform independent desktop... be customized as Swing API provides room for better customization of UI... Splash Screen in Java Swing Set Different Color
Java Swing Tutorial - Learning Java Swing programming step by step
Start. But mostly Java Swing is used to develop platform independent desktop... supports platform independence Application design can be customized as Swing API provides room for better customization of UI interfaces Swing
alignment
Alignment
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
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE123 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE123 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE123
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE124 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE124 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE124
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 footer
alignment 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
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE160 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE160 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE160
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE130 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE130 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE130
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE126 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE126 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE126
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE150 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE150 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE150
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE125 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE125 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE125
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE140 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE140 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE140
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE122 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE122 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE122
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE121 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE121 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE121
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE120-1 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE120-1 in Maven based Java projects
of org-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE120-1
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE120 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE120 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE120
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE113 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE113 in Maven based Java projects
-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE113
Maven dependency for org.netbeans.api - org-netbeans-modules-java-platform-ui version RELEASE120-u1 is released. Learn to use org-netbeans-modules-java-platform-ui version RELEASE120-u1 in Maven based Java projects
of org-netbeans-modules-java-platform-ui released The developers of   org.netbeans.api - org-netbeans-modules-java-platform-ui project have released...; org.netbeans.api - org-netbeans-modules-java-platform-ui library is RELEASE120-u1
Maven Repository/Dependency: org.netbeans.api | org-netbeans-modules-java-platform-ui
Maven Repository/Dependency of Group ID org.netbeans.api and Artifact ID org-netbeans-modules-java-platform-ui. Latest version of org.netbeans.api:org-netbeans-modules-java-platform-ui dependencies. # Version
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
Alignment in struts 2.0 - Struts
Alignment 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
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
ModuleNotFoundError: No module named 'sciencebeam-alignment'
ModuleNotFoundError: No module named 'sciencebeam-alignment'  Hi...: No module named 'sciencebeam-alignment' How to remove the ModuleNotFoundError: No module named 'sciencebeam-alignment' error? Thanks   Hi
ModuleNotFoundError: No module named 'face-alignment'
ModuleNotFoundError: No module named 'face-alignment'  Hi, My... named 'face-alignment' How to remove the ModuleNotFoundError: No module named 'face-alignment' error? Thanks   Hi, In your python
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   
Swing
Swing  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

Ads