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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandra shekhar
Swing UI alignment Issue on different Platform
7 Answer(s)      6 years and 3 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
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   
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
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
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
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
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
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
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
Different JRE
Different JRE  Java is platform independent. The why different JRE's there for differen operating systems
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
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
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
Eclipse Plunging/UI
Eclipse Plunging/UI         Mylyn Mylyn is a Task-Focused UI... the Eclipse UI on the interesting information, hide the uninteresting
Advertisements
 

 

 

DMCA.com