Total members 11894 |It is currently Fri Nov 22, 2024 10:35 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Using list with GridBagLayout and GridBagConstraints
java code
import java.awt.*;
import java.applet.Applet;

public class UsageList extends Applet {
TextArea output;
List listOne, listTwo;

public void init() {

//Build first list
listOne = new List(4, true);
listOne.addItem("x1");
listOne.addItem("x2");
listOne.addItem("x3");
listOne.addItem("x4");
listOne.addItem("x5");
listOne.addItem("x6");
listOne.addItem("x7");


listTwo = new List();
listTwo.addItem("y1");
listTwo.addItem("y2");
listTwo.addItem("y3");
listTwo.addItem("y4");
listTwo.addItem("y5");
listTwo.addItem("y6");
listTwo.addItem("y7");

//Add lists to the Applet.
GridBagLayout badLayout = new GridBagLayout();
setLayout(badLayout);


output = new TextArea(10, 40);
output.setEditable(false);
GridBagConstraints gridBagConstrain = new GridBagConstraints();
gridBagConstrain.fill = GridBagConstraints.BOTH;
gridBagConstrain.weightx = 1.0;
gridBagConstrain.weighty = 1.0;
gridBagConstrain.gridheight = 2;
badLayout.setConstraints(output, gridBagConstrain);
add(output);

GridBagConstraints bagConstrain = new GridBagConstraints();
bagConstrain.fill = GridBagConstraints.VERTICAL;
bagConstrain.gridwidth = GridBagConstraints.REMAINDER; //end row
badLayout.setConstraints(listOne, bagConstrain);
add(listOne);
badLayout.setConstraints(listTwo, bagConstrain);
add(listTwo);

validate();
}

public boolean action(Event e, Object arg) {
if (e.target instanceof List) {
String language = (e.target == listOne) ?
"listOne" : "listTwo";
output.appendText("Action event occurred on \""
+ (String)arg + "\" in "
+ language + ".\n");
}
return true;
}

public boolean handleEvent(Event e) {
if (e.target instanceof List) {
List list = (List)(e.target);
String language = (list == listOne) ?
"listOne" : "listTwo";

switch (e.id) {
case Event.LIST_SELECT:
int sIndex = ((Integer)e.arg).intValue();
output.appendText("Select event occurred on item #"
+ sIndex + " (\""
+ list.getItem(sIndex) + "\") in "
+ language + ".\n");
break;
case Event.LIST_DESELECT:
int dIndex = ((Integer)e.arg).intValue();
output.appendText("Deselect event occurred on item #"
+ dIndex + " (\""
+ list.getItem(dIndex) + "\") in "
+ language + ".\n");
}
}
return super.handleEvent(e);
}
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Using list with GridBagLayout and GridBagConstraints
 elements of a GridBagLayout organized     -  
 BorderFactory create EtchedBorder, Line Border,GridBagLayout     -  
 display list     -  
 reverse list     -  
 list swap in C++     -  
 List interface     -  
 Implementation of List     -  
 List all database in php     -  
 List C++ implementation     -  
 Sort a list     -  



Topic Tags

Java AWT






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com