Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT Swing UI alignment Issue on different Platform

Have Programming Question? Ask it here!
 
 
 


chandra shekhar
Swing UI alignment Issue on different Platform
7 Answer(s)      5 years and 10 months ago
Posted in : Swing AWT



Advertisement
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
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
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
Android Platform...
Android Platform...  I am willing to port a J2ME code on Android Platform.On eclipse, its giving some error issue,but actually those all are UI... Platform, On doing just certain changes
BoxLayout alignment
Java NotesBoxLayout alignment Component alignment Alignment is a property... you want all components in a box to have the same alignment (eg, left/top, center, or right/bottom). Set the X alignment for components in a vertical box
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
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
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
Alignment of Image in HTML
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 i.e top, middle... Alignment of Image in HTML   
JTABLE Issue
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... to go back for another search. Now issue is -- when I put some input data
platform independent
platform independent  what is difirence between machine independent and platform independent
Alignment in the Dojo Date Widget - Ajax
Alignment in the Dojo Date Widget  Is there any way to align misaligned text in a dojo date widget?   Hi Friend, Please visit the following links: http://www.roseindia.net/dojo/ http://www.roseindia.net/dojo/dojo
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
SwingWorker issue
... but if EDt waits woker thread to complete my UI will be frozen.... please suggest me a way to get object in my secound calss without making UI frozen
jdialogbox issue.
jdialogbox issue.  i have one button.when clicked on it has to show a dialog box.but even click on it several times it has to open dialog box only once. if it is already not opened atleast once,then only it has to open dialog
Pinting restful webservice request on UI.
Pinting restful webservice request on UI.  I want to print request XML for Restful webservice request in my UI application in swing. When a user clicks on xml request button, he/she sees xml request on the UI. I could print xml
Javeline Platform
Javeline Platform       Javaline is an open source Java & Javascript platform. Read full Description
Issue with Javascript
Issue with Javascript  Hi I created arrays in javascript in following way var myimages= new Array(); myimages[0]="iphone_pushups.png"; myimages[1]= "cricket.png"; myimages[2]= "july.png"; myimages[3]= "matrix.png
Cascade Issue
and which one. The property inverse is set to FALSE. I've looked up different... is a normalization table, the dices role a bit different. Thanks for any input
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
Different JRE
Different JRE  Java is platform independent. The why different JRE's there for differen operating systems
Make Paragraph and Set Alignment
alignment. To make a paragraph we use Paragraph("Text") constructor . To gives alignment we use setAlignment(int alignment). Code Description: setAlignment(int alignment): We can set
Multiple session problem - Swing AWT
Multiple session problem  I am working in a Linux based java swing... .A JPanel can only have one JDialog at a time.But mupltiple JPanel(on different JFrames) can be launched. While switching between JPanels I am facing issue
Eclipse Plunging/UI
Eclipse Plunging/UI         Mylyn Mylyn is a Task-Focused UI... the Eclipse UI on the interesting information, hide the uninteresting
UI Component lifecycle
UI Component lifecycle  Hi...... Explain the UIComponent lifecycle, including important methods like initialize(), createChildren(), etc. Thanks
swing
swing  How to make swing component auto-resizable when JFrame resize
swing
swing  Write a java swing program to delete a selected record from a table
Working With Alignment Using JSP for Excel
Working with alignment using jsp for excel  ... alignment of cells on an excel sheet. The packages we need to import are java.io..... setAlignment(HSSFCellStyle.ALIGN_CENTER): This method is used to set the alignment
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
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
Downloading and installing jQuery UI
Downloading and installing jQuery UI       Downloading and installing jQuery UI There are Three ways of downloading or adding  jQuery UI : First
jQuery UI effects
jQuery UI effects       jQuery UI effects effects.core.js The jQuery UI effects depends heavily on this file  This file is utilizes
semantic issue xcode 4.2
semantic issue xcode 4.2  I have updated xcode 4.0 to 4.2 .. but once i open any application in this new version of xcode ..it throws lots of semantic issue. Can anyone please explain why it occurs and how to resolve
Are JVM's platform independent?
Are JVM's platform independent?  Hi, Are JVM's platform independent?   Hi, Java Virtual MachineJVM)'s is not platform independent. JVM... Runtime Enviroment) . It provides the cross platform functionality to java
What is Java Swing?
What is Java Swing?       Here, you will know about the Java swing. The Java Swing provides the multiple platform independent APIs interfaces for interacting between the users
what are the components of java platform ?
what are the components of java platform ?  what are the components of java platform ? plz if any1 perfectly know help me to override my conflicts.plz explain briefly
UI Component initialized
UI Component initialized  Hi.... What are the methods called when a UI component is intialized in flex? give me a good example for that Thanks  Ans: There are three methods are called when a UIComponent
Resultset Issue in SQL
Resultset Issue in SQL  when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue. My code is: SELECT JOBDESCRIPTION,CATEGORY
Set Space Ratio and Alignment
alignment. You can make pdf with no space between the characters of a word . Code Description: setAlignment(int alignment... alignment). The alignment can be one of the following values
portability vs platform independent
portability vs platform independent  sir, pls tell me 1.the differences between platform independent and portability related to java technology 2.how java provides security 3.how can i prove servlet is a single instance
What is Java Platform
. So, JVM for windows is different from JVM of Linux. Java Platform consists...As a beginner you must first understand the about Java Platform and to get the answer of the frequently asked question "What is Java Platform?". The Java
Issue in JSF and Richfaces.
Issue in JSF and Richfaces.  Hi,I am with a issue in JSF and Richfaces.I have one add user page.In which i have fields Firstname,LastName,SecretID(which has Validate/suggest as links beside tat) ,Email address,city,state,country
Login issue using Servlet
Login issue using Servlet  Hi all, I need a code for login using servlet where in I want to check and validate user name and password from database also I want to check candidate's class (for ex. FY, SY, TY) if candidate's class
 

 

 

DMCA.com