Scroll Pane is causing a problem
Hi
I am developing an application for BlackBerry Playbook in action script
I am having a problem with scrollpane that is the screen below the top focused screen disappears when i scroll the top screen.
Both screens are movieclip contained in a scrollpane.
like i have a screen M1 and M2 both are contained in a seperate scrollpane. After initialisation of both screens, one of the screen disappears when i scroll the other one. The screen that disappears is the one below the screen on top (which is being viewed or has the focus).
One thing i noticed was if i scroll the screen , scrolling event is passed to the screen below it hence it tends to scroll as well and when i navigate to that screen it disappears.
Please help me out
The AIR forum is probably a better place to ask this.
http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/bd-p/tablet
Be sure to include a code snippet demonstrating your problem.
Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Similar Messages
-
Problem with adding text area in scroll pane
hi , i have been facing this funny problem , but cant able to get solution.
the problem is i am trying to add text area in scroll pane , but when i add textarea in scroll pane using scrollpane.add(textarea) that text area remain disable always. i tried making it enable explicility but that code is not working.You don't use the add(...) method for JScrollPane. Use:
a) new JScrollPane( textArea );
b) scrollPane.getViewport().setView( textArea ); -
New to Applets: Problems wiht writing to files and with scroll panes.
Hi, I've recently graduated from university and so I have limited experience in java programming and I'm having some trouble with JApplets (this is the first time I've made one). I'm trying to make a simple program that will allow users to pick one of a few background images from a list (a list of jpanels within a scroll pane) then at the click of a button will output a CSS with the background tag set to the image location. This is for use on a microsoft sharepoint site where each user has a My-Sit area which I want to be customizable.
So far I've been creating this program as an application rather than a JApplet and just having another class that extends the JApplet Class which then displays the JFrame from the GUI Class. This initially didnt work because I was trying to add a window to a container so I kept programming it as an application until I got it working before trying to convert it to a JApplet. I solved the previous problem by changing my GUI class to extend JPanel instead of JFrame and it now displays correctly but with a coupe of issues.
Firstly the applet will not create/write to the CSS file. I read that applets couldnt read/write to the users file system but they could to their own. The file I wish to write to is kept on the same machine as the applet so I'm not sure why this isn't working.
Secondly the scroll panel is no longer working properly. This worked fine when I was still running the program as an application when the GUI still extended JFrame instead of JPanel (incidentally the program no longer runs as an application in this state) but now the scroll bar does not appear. This is a problem since I want the applet to remain the same size on the page even if I decide to add more backgrounds to the list. I tried setting the applet height/width to smaller values in the html file to see if the scroll bar would appear if the area was smaller than the GUI should be, but this just meant the bottom off the applet was cut off.
Could anyone offer any suggestion as to why these thigns arnt working and how to fix them? If necessary I can post my source code here. Thanks in advance.Ok, well my program is made up of 4 classes, I hope this isnt too much to be posting. If any explaination is needed then I'll post that next. Theres lots of print lines scattered aroudn due to me trying to fix this and theres some stuff commented out from when the program used to be an application isntead of an applet.
GUI Class, this was the main class until I made a JApplet Class
public class AppletGUI extends JPanel{
*GUI Components*
//JFrames
JFrame mainGUIFrame = new JFrame();
JFrame changeBackgroundFrame = new JFrame();
//JPanels (Sub-panels are indented)
JPanel changeBackgroundJP = new JPanel(new BorderLayout());
JPanel changeBackgroundBottomJP = new JPanel(new GridLayout(1,2));
JPanel backgroundJP = new JPanel(new GridLayout(1,2));
JPanel selectBackground = new JPanel(new GridLayout(1,2));
//Jbuttons
JButton changeBackgroundJB = new JButton("Change Background");
JButton defaultStyleJB = new JButton("Reset Style");
//JLabels
JLabel changeBackgroundJL = new JLabel("Choose a Background from the Menu");
JLabel backgroundJL = new JLabel();
//JScrollPane
JScrollPane backgroundList = new JScrollPane();
JPanel backgroundListPanel = new JPanel(new GridLayout());
//Action Listeners
ButtonListener bttnLstnr = new ButtonListener();
//Controllers
CSSGenerator cssGenerator = new CSSGenerator();
Backgrounds backgroundsController = new Backgrounds();
backgroundMouseListener bgMouseListener = new backgroundMouseListener();
//Flags
Component selectedComponent = null;
*Colour Changer*
//this method is used to change the colour of a selected JP
//selected JPs have their background darkered and when a
//different JP is selected the previously seleced JP has its
//colour changed back to it's original.
public void changeColour(JPanel theJPanel, boolean isDarker){
//set selected JP to a different colour
Color tempColor = theJPanel.getBackground();
if(isDarker){
tempColor = tempColor.darker();
else{
tempColor = tempColor.brighter();
theJPanel.setBackground(tempColor);
//also find any sub-JPs and change their colour to match
int j = theJPanel.getComponents().length;
for(int i = 0; i < j; i++){
String componentType = theJPanel.getComponent(i).getClass().getSimpleName();
if(componentType.equals("JPanel")){
theJPanel.getComponent(i).setBackground(tempColor);
*Populating the GUI*
//backgroundList.add();
//Populating the Backgrounds List
*Set Component Size Method*
public void setComponentSize(Component component, int width, int height){
Dimension tempSize = new Dimension(width, height);
component.setSize(tempSize);
component.setMinimumSize(tempSize);
component.setPreferredSize(tempSize);
component.setMaximumSize(tempSize);
*Constructor*
public AppletGUI() {
//REMOVED CODE
//AppletGUI.setDefaultLookAndFeelDecorated(true);
//Component Sizes
//setComponentSize
//Adding Action Listeners to Components
System.out.println("adding actions listeners to components");
changeBackgroundJB.addActionListener(bttnLstnr);
defaultStyleJB.addActionListener(bttnLstnr);
//Populating the Change Background Menu
System.out.println("Populating the window");
backgroundsController.populateBackgroundsData();
backgroundsController.populateBackgroundsList();
//loops to add background panels to the JSP
ArrayList<JPanel> tempBackgroundsList = new ArrayList<JPanel>();
JPanel tempBGJP = new JPanel();
tempBackgroundsList = backgroundsController.getBackgroundsList();
int j = tempBackgroundsList.size();
JPanel backgroundListPanel = new JPanel(new GridLayout(j,1));
for(int i = 0; i < j; i++){
tempBGJP = tempBackgroundsList.get(i);
System.out.println("Adding to the JSP: " + tempBGJP.getName());
//Add Mouse Listener
tempBGJP.addMouseListener(bgMouseListener);
backgroundListPanel.add(tempBGJP, i);
//set viewpoing
backgroundList.setViewportView(backgroundListPanel);
/*TESTING
System.out.println("\n\n TESTING!\n Printing Content of SCROLL PANE \n");
j = tempBackgroundsList.size();
for(int i = 0; i < j; i++){
System.out.println(backgroundList.getComponent(i).getName());
changeBackgroundJP.add(changeBackgroundJL, BorderLayout.NORTH);
changeBackgroundJP.add(backgroundList, BorderLayout.CENTER);
//changeBackgroundJP.add(tempBGJP, BorderLayout.CENTER);
changeBackgroundJP.add(changeBackgroundBottomJP, BorderLayout.SOUTH);
changeBackgroundBottomJP.add(changeBackgroundJB);
changeBackgroundBottomJP.add(defaultStyleJB);
System.out.println("Finsihed populating");
//REMOVED CODE
//adding the Background Menu to the GUI and settign the GUI options
//AppletGUI.setDefaultLookAndFeelDecorated(true);
//this.setResizable(true);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(500,500);
this.setSize(400,300);
this.add(changeBackgroundJP);
//REMOVED CODE
*Main Method*
public static void main(String[] args){
System.out.println("Creating GUI");
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
System.out.println("GUI Displayed");
*Button Listener Inner Class*
public class ButtonListener implements ActionListener{
//check which button is clicked
public void actionPerformed(ActionEvent event) {
AbstractButton theButton = (AbstractButton)event.getSource();
//Default Style Button
if(theButton == defaultStyleJB){
System.out.println("Default Style Button Clicked!");
//Change Background Button
if(theButton == changeBackgroundJB){
System.out.println("Change Background Button Clicked!");
String backgroundURL = cssGenerator.getBackground();
if(backgroundURL != ""){
cssGenerator.setBackgroundChanged(true);
cssGenerator.setBackground(backgroundURL);
cssGenerator.outputCSSFile();
System.out.println("Backgroudn Changed, CSS File Written");
else{
System.out.println("No Background Selected");
*Mouse Listener Inner Class*
public class backgroundMouseListener implements MouseListener{
public void mouseClicked(MouseEvent e){
//get component
JPanel tempBackgroundJP = new JPanel();
tempBackgroundJP = (JPanel)e.getComponent();
System.out.println("Background Panel Clicked");
//change component colour
if(selectedComponent == null){
selectedComponent = tempBackgroundJP;
else{
changeColour((JPanel)selectedComponent, false);
selectedComponent = tempBackgroundJP;
changeColour((JPanel)selectedComponent, true);
//set background URL
cssGenerator.setBackground(tempBackgroundJP.getName());
public void mousePressed(MouseEvent e){
public void mouseReleased(MouseEvent e){
public void mouseEntered(MouseEvent e){
public void mouseExited(MouseEvent e){
}JApplet Class, this is what I plugged the GUI into after I made the change from Application to JApplet.
public class AppletTest extends JApplet{
public void init() {
System.out.println("Creating GUI");
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
Container content = getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
content.add(theGUI);
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
setContentPane(theGUI);
System.out.println("GUI Displayed");
public static void main(String[] args){
AppletTest at = new AppletTest();
at.init();
at.start();
}The CSS Generator Class. This exists because once I have the basic program working I intend to expand upon it and add multiple tabs to the GUI, each one allowing the user to change different style options. Each style option to be changed will be changed wit ha different method in this class.
public class CSSGenerator {
//Variables
String background = "";
ArrayList<String> backgroundCSS;
//Flags
boolean backgroundChanged = false;
//Sets and Gets
//For Variables
public void setBackground(String theBackground){
background = theBackground;
public String getBackground(){
return background;
//For Flags
public void setBackgroundChanged(boolean isBackgroundChanged){
backgroundChanged = isBackgroundChanged;
public boolean getBackgroundChanged(){
return backgroundChanged;
//background generator
public ArrayList<String> backgroundGenerator(String backgroundURL){
//get the URL for the background
backgroundURL = background;
//creat a new array list of strings
ArrayList<String> backgroundCSS = new ArrayList<String>();
//add the strings for the background options to the array list
backgroundCSS.add("body");
backgroundCSS.add("{");
backgroundCSS.add("background-image: url(" + backgroundURL + ");");
backgroundCSS.add("background-color: #ff0000");
backgroundCSS.add("}");
return backgroundCSS;
//Write CSS to File
public void outputCSSFile(){
try{
//Create CSS file
System.out.print("creating file");
FileWriter cssWriter = new FileWriter("C:/Documents and Settings/Gwilym/My Documents/Applet Data/CustomStyle.css");
System.out.print("file created");
System.out.print("creating buffered writer");
BufferedWriter out = new BufferedWriter(cssWriter);
System.out.print("buffered writer created");
//check which settings have been changed
//check background flag
if(getBackgroundChanged() == true){
System.out.print("retrieving arraylist");
ArrayList<String> tempBGOptions = backgroundGenerator(getBackground());
System.out.print("arraylist retrieved");
int j = tempBGOptions.size();
for(int i = 0; i < j ; i++){
System.out.print("writing to the file");
out.write(tempBGOptions.get(i));
out.newLine();
System.out.print("written to the file");
out.close();
}catch (Exception e){//Catch exception if any
System.out.println("Error: Failed to write CSS file");
/** Creates a new instance of CSSGenerator */
public CSSGenerator() {
}The Backgrounds Class. This class exists because I didnt want there to just be a hardcoded lsit of backgrounds, I wanted it to be possible to add new ones to the list without simply lettign users upload their own images (since the intended users are kids and this sharepoint site is used for educational purposes, I dont want them uplaoded inapropraite backgrounds) but I do want the site admin to be able to add more images to the list. for this reason the backgrounds are taken from a list in a text file that will be stored in the same location as the applet, the file specifies the background name, where it is stored, and where a thumbnail image is stored.
public class Backgrounds {
//Array Lists
private ArrayList<JPanel> backgroundsList;
private ArrayList<String> backgroundsData;
//Set And Get Methods
public ArrayList getBackgroundsList(){
return backgroundsList;
//ArrayList Population Methods
public void populateBackgroundsData(){
//decalre the input streams and create a new fiel hat points to the BackgroundsData file
File backgroundsDataFile = new File("C:/Documents and Settings/Gwilym/My Documents/Applet Data/BackgroundsData.txt");
FileInputStream backgroundsFIS = null;
BufferedInputStream backgroundsBIS = null;
DataInputStream backgroundsDIS = null;
try {
backgroundsFIS = new FileInputStream(backgroundsDataFile);
backgroundsBIS = new BufferedInputStream(backgroundsFIS);
backgroundsDIS = new DataInputStream(backgroundsBIS);
backgroundsData = new ArrayList<String>();
String inputtedData = null;
//loops until it reaches the end of the file
while (backgroundsDIS.available() != 0) {
//reads in the data to be stored in an array list
inputtedData = backgroundsDIS.readLine();
backgroundsData.add(inputtedData);
//TESTING
System.out.println("\n\nTESTING: populateBackgroundsData()");
int j = backgroundsData.size();
for(int i = 0; i < j; i++){
System.out.println("Index " + i + " = " + backgroundsData.get(i));
System.out.println("\n\n");
//close all stremas
backgroundsFIS.close();
backgroundsBIS.close();
backgroundsDIS.close();
} catch (FileNotFoundException e) {
System.out.println("Error: File Not Found");
} catch (IOException e) {
System.out.println("Error: IO Exception Thrown");
public void populateBackgroundsList(){
backgroundsList = new ArrayList<JPanel>();
int j = backgroundsData.size();
System.out.println("number of backgrounds = " + j);
backgroundsList = new ArrayList<JPanel>();
for(int i = 0; i < j; i++){
String tempBackgroundData = backgroundsData.get(i);
JPanel backgroundJP = new JPanel(new GridLayout(1,2));
JLabel backgroundNameJL = new JLabel();
JLabel backgroundIconJL = new JLabel();
//split the string string and egt the background name and URL
String[] splitBGData = tempBackgroundData.split(",");
String backgroundName = splitBGData[0];
String backgroundURL = splitBGData[1];
String backgroundIcon = splitBGData[2];
System.out.println("\nbackgroundName = " + backgroundName);
System.out.println("\nbackgroundURL = " + backgroundURL);
System.out.println("\nbackgroundIcon = " + backgroundIcon + "\n");
backgroundNameJL.setText(backgroundName);
backgroundIconJL.setIcon(new javax.swing.ImageIcon(backgroundIcon));
backgroundJP.add(backgroundNameJL);
backgroundJP.add(backgroundIconJL);
backgroundJP.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
//Name the JP as the background URL so it can be found
//May be useful sicne the data file may need to contain 3 fields in future
//this is incase the preview image (icon) is different from the acctual background
//most liekly in the case of more complex ppictures rather then repeating patterns
backgroundJP.setName(backgroundURL);
//Add the JP to the Array List
backgroundsList.add(backgroundJP);
//TESTING
System.out.println("\n\nTESTING: populateBackgroundsList()");
j = backgroundsList.size();
for(int i = 0; i < j; i++){
System.out.println("Index " + i + " = " + backgroundsList.get(i));
System.out.println("\n\n");
}So thats my program so far, if theres anythign that needs clarifying then please jsut ask. Thank you very much for the help! -
I have background in as3, but this is my first attempt at
building an application with classes.
I have a scrollpane that populates with an image.
MyScroll.as
public var sp:ScrollPane=new ScrollPane();
public var imagePath:String = "images/cover.jpg";
public function createScrollPane(imagePath:String):void {
sp.move(0,40);
sp.source = imagePath;
addChild(sp);
I have a navigation at the bottom that returns the image name
from an array that I want to refresh/load/source the scrollpane
with, but none will work!
SpreadNav.as
public function _loadPage(evt:MouseEvent) {
var str:String = evt.target.name;
var mySlice = str.substr(10);
myLoadImages.loadImage();
myScrollCall.reCreateScrollPane(myNpXMLToArray.highArray[mySlice]);
I also have a button generated that does reload the
scrollpane, so I know that it can replace the source.
MyScroll.as
public function setClick():void {
var refreshButton:Button = new Button();
refreshButton.emphasized = true;
refreshButton.label = "refreshPane()";
refreshButton.move(10, 10);
refreshButton.addEventListener(MouseEvent.CLICK,
clickHandler);
addChild(refreshButton);
public function clickHandler(event:MouseEvent):void {
sp.source = "images/1.jpg";
But when I try to load it from the array nothing
happens...and I have tried putting the image name right in there,
from the array, refresh, source, contentPath is old, redraw(true)
is old and I am running out of things to try
MyScroll.as
public function reCreateScrollPane(imagePath2:String):void {
//imagePath2 = "images/cover.jpg";
var url:String = "images/"+imagePath2;
trace(url);
sp.load(new URLRequest(url));
trace("scroll pane refreshed");
sp.addEventListener(ProgressEvent.PROGRESS, progressHandler);
sp.addEventListener(Event.COMPLETE, completeHandler);
sp.source = "images/"+imagePath2;
//sp.source = "images/cover.jpg";
Can anyone suggest a solution?
Thanksi wonder why i bother with this forum sometimes. i always end
up answering my own questions an hour later. so the problem was
that the testes.swf was using a startDrag function and the
scrollPane in which it resided has its startDrag set to true. i
guess you can't have both elements dragging at the same time. would
cause serious upset. so yeah, there you go. -
Using a SDHC card adapter I can import directly on my iPad2 videos (.mov) taken with a Panasonic DMC-ZS3. The same video files (same file format) imported in Aperture 3.3 cannot be synchronized with iPad. Is Aperture causing the problem?
Oh, baby! This bad boy flies!! Here's what to expect:
I had 40,000 images in Aperture 3 and it was dog slow at everything. I installed 3.1 update today. It took 5 minutes to update the database and then behaved marginally better than before at ASIC library navigation. I was disappointed.
Then I QUIT the app. It took a couple of hours to "update files for sharing" with a counter that went to 110,000 images. So it must have updated every thumbnail and variation of preview. Turned it back on , and BAM. Came up fully in seconds. Paused for 10 seconds ten everything was lickrty split. For the first time ever, I can use the Projects view with all 791 projects and scroll quickly. I even put it in photos modevand whipped thru all 49,000 images!
Haven't done anybprocessing yet, but i'm liking it!!
Jim -
ImageIO image renders slow in scroll pane
Hello all, I need some help understanding the behavior of BufferedImage(s)
retrieved from ImageIO.read(). The problem I am having is weird .. I load
a PNG image via ImageIO.read(), I use it to construct an ImageIcon which
is later used in a JLabel/JScrollPane for rendering. When I attempt
to scroll the image in the scroll pane, it is very chunky and slow.
If I load the same image with ImageIcon(byte[]), there is no problem. The
image on disk is 186k, when loaded from ImageIcon(), it consumes about
10M, when loaded with ImageIO about 5M is consumed ... when I scroll,
the memory usage increase about 9 MB, which can be collected immediatly
to return to 5M.
Is ImageIO doing some fancy optimization to preserve memory, if so ... how
can I alter the settings or turn it off completly. I tried setting
ImageIO.setUseCache(false); that did nothing as far as I can tell.
The code to load the image is as follows, I am just using the default right now.
// perform base64 decoding from buffer
ByteArrayInputStream bos = new ByteArrayInputStream(decoded);
try
image = ImageIO.read(bos);
catch (IOException ioe)
}Any help would be greatly appreciated!!!
Cheers,
JodyI'm not sure if this is exactly what you are looking for but, here's code that works well for me:
private class MyJLabel extends JLabel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
URL imageLocation = MyJPanel.class.getResource("myImage.jpg");
Image myImage = Toolkit.getDefaultToolkit().getImage (imageLocation);
MediaTracker tracker = new MediaTracker (this);
tracker.addImage(myImage, 0);
try { tracker.waitForID(0); } catch (InterruptedException exception) { System.out.println("Image myImage.jpg wasn't loaded!"); }
g2d.drawImage(myImage, 0, 0, getWidth(), getHeight, this);
}Once I reload images using the above method, image repainting is very quick. Extend the JLabel (MyJLabel) to overwrite the paint method as above. Should work fast when you do so. You can move the image retrieving code out of the paint method and into the 'MyJLabel' constructor.
How are you painting the icon and where are you retrieving the image? Can you post more code?
Regards,
Devyn -
How to re-position scroll pane contents?
I have a JSplitPane where the top half of the component contains a list of topics and the bottom half contains a scroll pane with a text area inside it. The user clicks a list item and the text for it is shown below it.
The problems is when the text area exceeds the viewable area, the bottom-most portion of the text is shown instead of the top-most portion. In other words, if the text contains 6 lines and the viewable area is 4 lines, I'm seeing lines 3-6 instead of 1-4.
One would think this is a very easy solution, such as:
SplitTextScrollPane.getVerticalScrollBar().setValue(0);
However, that doesn't work (at least not in JDK 1.3.0c). How do you programatically scroll the text back to the top line?
Thank you.Thanks, that worked.
I'm still a little curious about how to manually control the position of a scrollpane's contents -- for example, when the scroll pane contains things besides a text area (such as a JList or something). -
Just wanted to know how can we add a scroll pane in Dream
weaver 8.
Any other way we can avoid a vertical scroll for the content,
and by freezing its size at 1024 by 768 and a scroll pane inside
the same.
SanDid you ever find a solution? I too have this problem and I
have to upload a few files at a time and then wait and often have
to restart my DSl modem to get going again. I can upload and
downlaoad all day with a browser and email but as soon as Iose DW I
am sure to loose the connection. -
Selecting Multiple Images from Scroll Pane
Hi,
I am quite a newbie to Java GUI and can't find a good example on something I wish to do. I got a scroll pane which actually loaded images as a Label. I do this program to upload the images. I already manage to upload the images somehow. But now the problem is I wish to remove the images from the scroll pane. It will be something like this.
1. Try to put a check box on each JLabel with the image.
2. Select multiple JLabel images by selecting the check boxes.
3. Click on the "Remove" button will remove those JLabel Images which has a check box "checked"
What I am not too sure is,
how can I be able to detect a group of checkboxes which is checked inside the scroll pane. So that I can actually removes them from the scroll pane. Can anyone show me a good example for it?Keep the check boxes in a Collection of some sort. Iterate through it, calling isSelected() on each box.
Or, add a listener to the checkboxes so that a list of selected images is updated whenever a box is checked or unchecked.
One of these may suit better than the other depending on circumstances. -
Setting scroll pane initial display size
hello.
how can i modify the modified code below so that users of my video library system would be able to view CD/DVD/Game information by name, age category, type and year? the text area is not displaying in a proper size - i have to use the scroll pane to view the data in the text area. i should be able to view the data in the text area without a scrollpane because there is not much data in the database. how can i make the text area bigger?
thanks.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ViewProductDetails extends JFrame{
JPanel pnlBox, pnlBody, pnlFooter;
JCheckBox name;
JCheckBox ageCategory;
JCheckBox type;
JCheckBox year;
JButton returnToProductMenu;
JTextArea jta;
Container contentpane;
Connection db;
Statement statement;
public void makeConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(Exception e){
System.out.println("Problem loading the driver");
public void setHostURL(){
String url = "jdbc:odbc:VideoLibrary";
closeDB();
try{
db = DriverManager.getConnection(url,"","");
statement = db.createStatement();
DatabaseMetaData dbmd = db.getMetaData();
ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"});
catch(Exception e){
System.out.println("Could not initialise the database");
e.printStackTrace();
public void selectProductOne(){
try{
ResultSet rs1 = statement.executeQuery("SELECT * FROM Product ORDER BY name");
ResultSetMetaData rsmd1 = rs1.getMetaData();
for(int i = 1; i <= rsmd1.getColumnCount(); i++){
jta.append(rsmd1.getColumnName(i) + " ");
jta.append("\n");
while(rs1.next()){
for(int i = 1; i <= rsmd1.getColumnCount(); i++){
jta.append(rs1.getObject(i) + " ");
jta.append("\n");
catch(SQLException ea){
ea.printStackTrace();
public void selectProductTwo(){
try{
ResultSet rs2 = statement.executeQuery("SELECT * FROM Product ORDER BY ageCategory");
ResultSetMetaData rsmd2 = rs2.getMetaData();
for(int i = 1; i <= rsmd2.getColumnCount(); i++){
jta.append(rsmd2.getColumnName(i) + " ");
jta.append("\n");
while(rs2.next()){
for(int i = 1; i <= rsmd2.getColumnCount(); i++){
jta.append(rs2.getObject(i) + " ");
jta.append("\n");
catch(SQLException eb){
eb.printStackTrace();
public void selectProductThree(){
try{
ResultSet rs3 = statement.executeQuery("SELECT * FROM Product ORDER BY type");
ResultSetMetaData rsmd3 = rs3.getMetaData();
for(int i = 1; i <= rsmd3.getColumnCount(); i++){
jta.append(rsmd3.getColumnName(i) + " ");
jta.append("\n");
while(rs3.next()){
for(int i = 1; i <= rsmd3.getColumnCount(); i++){
jta.append(rs3.getObject(i) + " ");
jta.append("\n");
catch(SQLException ec){
ec.printStackTrace();
public void selectProductFour(){
try{
ResultSet rs4 = statement.executeQuery("SELECT * FROM Product ORDER BY year");
ResultSetMetaData rsmd4 = rs4.getMetaData();
for(int i = 1; i <= rsmd4.getColumnCount(); i++){
jta.append(rsmd4.getColumnName(i) + " ");
jta.append("\n");
while(rs4.next()){
for(int i = 1; i <= rsmd4.getColumnCount(); i++){
jta.append(rs4.getObject(i) + " ");
jta.append("\n");
catch(SQLException ed){
ed.printStackTrace();
public void closeDB(){
try{
if(statement != null){
statement.close();
if(db != null){
db.close();
catch(Exception e){
System.out.println("Could not close the current connection");
e.printStackTrace();
public ViewProductDetails(){
super("View Product Details");
contentpane = getContentPane();
contentpane.setLayout(new BorderLayout());
pnlBox = new JPanel();
pnlBody = new JPanel();
pnlFooter = new JPanel();
jta = new JTextArea();
jta.setFont(new Font("Serif", Font.PLAIN, 12));
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
jta.setEditable(false);
name = new JCheckBox("Name");
ageCategory = new JCheckBox("Age Category");
type = new JCheckBox("Type");
year = new JCheckBox("Year");
pnlBox.add(name);
pnlBox.add(ageCategory);
pnlBox.add(type);
pnlBox.add(year);
JScrollPane jsp = new JScrollPane(jta);
pnlBody.add(jsp, BorderLayout.CENTER);
returnToProductMenu = new JButton("Return To Product Menu");
pnlFooter.add(returnToProductMenu);
contentpane.add(pnlBox,BorderLayout.NORTH);
contentpane.add(pnlBody,BorderLayout.CENTER);
contentpane.add(pnlFooter,BorderLayout.SOUTH);
pack();
setLocationRelativeTo(null);
setVisible(true);
name.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductOne();
closeDB();
ageCategory.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductTwo();
closeDB();
type.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductThree();
closeDB();
year.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductFour();
closeDB();
returnToProductMenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
public static void main(String[] args){
new ViewProductDetails();
}hello.
thanks for the reply. i did what you told me to do. but when i compile the program i get the following error (both error + code are shown below).
----jGRASP exec: javac -g E:\CP4B Project\ViewProductDetails.java
ViewProductDetails.java:174: cannot find symbol
symbol : method setPreferredSize()
location: class javax.swing.JScrollPane
jsp.setPreferredSize();
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ViewProductDetails extends JFrame{
JPanel pnlBox, pnlBody, pnlFooter;
JCheckBox name;
JCheckBox ageCategory;
JCheckBox type;
JCheckBox year;
JButton returnToProductMenu;
JTextArea jta;
Container contentpane;
Connection db;
Statement statement;
public void makeConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(Exception e){
System.out.println("Problem loading the driver");
public void setHostURL(){
String url = "jdbc:odbc:VideoLibrary";
closeDB();
try{
db = DriverManager.getConnection(url,"","");
statement = db.createStatement();
DatabaseMetaData dbmd = db.getMetaData();
ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"});
catch(Exception e){
System.out.println("Could not initialise the database");
e.printStackTrace();
public void selectProductOne(){
try{
ResultSet rs1 = statement.executeQuery("SELECT * FROM Product ORDER BY name");
ResultSetMetaData rsmd1 = rs1.getMetaData();
for(int i = 1; i <= rsmd1.getColumnCount(); i++){
jta.append(rsmd1.getColumnName(i) + " ");
jta.append("\n");
while(rs1.next()){
for(int i = 1; i <= rsmd1.getColumnCount(); i++){
jta.append(rs1.getObject(i) + " ");
jta.append("\n");
catch(SQLException ea){
ea.printStackTrace();
public void selectProductTwo(){
try{
ResultSet rs2 = statement.executeQuery("SELECT * FROM Product ORDER BY ageCategory");
ResultSetMetaData rsmd2 = rs2.getMetaData();
for(int i = 1; i <= rsmd2.getColumnCount(); i++){
jta.append(rsmd2.getColumnName(i) + " ");
jta.append("\n");
while(rs2.next()){
for(int i = 1; i <= rsmd2.getColumnCount(); i++){
jta.append(rs2.getObject(i) + " ");
jta.append("\n");
catch(SQLException eb){
eb.printStackTrace();
public void selectProductThree(){
try{
ResultSet rs3 = statement.executeQuery("SELECT * FROM Product ORDER BY type");
ResultSetMetaData rsmd3 = rs3.getMetaData();
for(int i = 1; i <= rsmd3.getColumnCount(); i++){
jta.append(rsmd3.getColumnName(i) + " ");
jta.append("\n");
while(rs3.next()){
for(int i = 1; i <= rsmd3.getColumnCount(); i++){
jta.append(rs3.getObject(i) + " ");
jta.append("\n");
catch(SQLException ec){
ec.printStackTrace();
public void selectProductFour(){
try{
ResultSet rs4 = statement.executeQuery("SELECT * FROM Product ORDER BY year");
ResultSetMetaData rsmd4 = rs4.getMetaData();
for(int i = 1; i <= rsmd4.getColumnCount(); i++){
jta.append(rsmd4.getColumnName(i) + " ");
jta.append("\n");
while(rs4.next()){
for(int i = 1; i <= rsmd4.getColumnCount(); i++){
jta.append(rs4.getObject(i) + " ");
jta.append("\n");
catch(SQLException ed){
ed.printStackTrace();
public void closeDB(){
try{
if(statement != null){
statement.close();
if(db != null){
db.close();
catch(Exception e){
System.out.println("Could not close the current connection");
e.printStackTrace();
public ViewProductDetails(){
super("View Product Details");
contentpane = getContentPane();
contentpane.setLayout(new BorderLayout());
pnlBox = new JPanel();
pnlBody = new JPanel();
pnlFooter = new JPanel();
jta = new JTextArea();
jta.setFont(new Font("Serif", Font.PLAIN, 12));
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
jta.setEditable(false);
name = new JCheckBox("Name");
ageCategory = new JCheckBox("Age Category");
type = new JCheckBox("Type");
year = new JCheckBox("Year");
pnlBox.add(name);
pnlBox.add(ageCategory);
pnlBox.add(type);
pnlBox.add(year);
JScrollPane jsp = new JScrollPane(jta);
jsp.setPreferredSize();
pnlBody.add(jsp, BorderLayout.CENTER);
returnToProductMenu = new JButton("Return To Product Menu");
pnlFooter.add(returnToProductMenu);
contentpane.add(pnlBox,BorderLayout.NORTH);
contentpane.add(pnlBody,BorderLayout.CENTER);
contentpane.add(pnlFooter,BorderLayout.SOUTH);
pack();
setLocationRelativeTo(null);
setVisible(true);
name.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductOne();
closeDB();
ageCategory.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductTwo();
closeDB();
type.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductThree();
closeDB();
year.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeConnection();
setHostURL();
selectProductFour();
closeDB();
returnToProductMenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
public static void main(String[] args){
new ViewProductDetails();
} -
Scrolling pane to view selected node
I have a JTree which is inside of a JScrollPane. I sometimes use setSelectionPath(TreePath) to expand a particular Node, but usually it's outside of the viewing area so you don;t notice it. What's the easiest way to get the scroll pane to scroll so the newly selected node is visible?
no problem! I haven't figured how to start that project yet... may take a while before I can find a way to do it. Hey thanks for the link, works great now
-
Using pen button to scroll / pan with default drivers
Hi all,
On a previous tablet pc I owned, I was able to set the pen button to be used to scroll / pan instead of right click. Using the default Lenovo drivers, I see an option to deselect "use pen button as right click", but I don't see where I can instead choose the scrolling option. Does that require the Wacom drivers to be installed? I'm trying to avoid that, since I don't need pressure sensitivity much and I seem to be the only person on this forum whose pen + touch isn't giving me problems, so don't want to unnecessarily change drivers.
Thanks!You need to test what the SelectedIndex is before you add or subtract 1 from the SelectedIndex.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'move up through the items
If ListBox1.Items.Count > 0 Then
If ListBox1.SelectedIndex <= 0 Then
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Else
ListBox1.SelectedIndex -= 1
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'move down through the items
If ListBox1.Items.Count > 0 Then
If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
ListBox1.SelectedIndex = 0
Else
ListBox1.SelectedIndex += 1
End If
End If
End Sub
If you say it can`t be done then i`ll try it -
Putting an image in a scroll pane
This is probably a simple question for most of you, but I need a little bit of help. How do I put a picture in a scroll pane?
The problem I have is that I can load an image and display it, that works fine. However, let's say I am making a new frame (I generally use JFrames), and I want to have a scroll pane in it. Let's also say I have numerous buttons around the edges (using a BorderLayout, or something). How do I load an image, draw the image on-screen and have it so that it only shows up in the scroll pane without the scrollbars disappearing?
I try to do it now, but for some reason the scroll bars of the scroll pane never show up. I can make the entire image be displayed by dragging the window edges bigger (the normal way you make windows bigger), and then I can see the entire picture. Unfortunately, the scroll bars on the scroll pane never show up if the window is too small to display the entire image. This is very puzzling, because I really don't know what I'm doing wrong. I have tried putting a panel in the scroll pane, and drawing on the panel, but still no scroll bars show up on the scroll pane if it is not big enough to show the entire picture / panel.
I am sure that the solution is very simple, but right now that solution eludes me.There's an example in the swing tutorials that seems to me to do exactly what you want.
See if http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html does the job, (less the border layout and buttons of course, but that shouldn't be too hard once you get the scroll bars working).
I believe the default scrollbar policy will let the scroll bars appear only when needed based on the bounds and the preferred size.
I used the example to set up a scrolling map (still just a gif image) and it works fine. If you still have trouble, you probably need to post the relevant section of code. -
Use "next" and "previous" buttons in two scroll panes
Hello, I have a question about how to use next and previous buttons in two scroll panes. In fact, I plan to display two similar files (HTML) in two scroll panes seperately. the purpose is to find their differences, highlight these differences and finally traverse these differences one by one by using next and previous buttons.
To realize this function, how should I mark their differences so that next and prevous buttons can recognize their locations? does anyone have idea?
Thank you very much.Can "focus" resolve this problem? But how should I add focus to a line in one HTML files? Thank you.
-
Scroll pane not working on Intranet
I used scroll pane component from flash mx 2004 professional
. and loaded movie clip in it , when this file run on single
machine with flash player 7 it works properly , but when I put it
on intranet , scrollpane doesn’t work , movie get loaded in
it , but scrollpane is not visible , to work it properly I have to
change Internet explorer setting . In multimedia setting I have to
‘enable don't display online media content in the media bar
‘ this setting , after this scrollpane works properly , is
there any other solution for it . or tell me why its not working
properly , it is problem of Internet explorer version or flash
player version.
please give me a solution for it, its argent ,
i m waiting for replayI see in a lot of forums from 2004 that this is an issue !
and Macromedia hasnt done anything about it till now is surprising
and frustrating! and no help to solve it either! that is ridiculous
now!
TP
Maybe you are looking for
-
Firefox won't open in Windows 8.1 after latest update failed to install
Latest update for firefox failed to install. Now, when I try to open firefox, I get the hourglass circle and then....Nothing. Check the processes and it is showing as a background process, but not doing anything. No error message, no crash alert. So,
-
Does anyone know why I would get this message from a Time Capsule:The backup disk image "/Volumes/Data/John Tozzi's MacBook Pro.sparsebundle" is already in use? One minute it works fine and then I get this error message with no change in any setting
-
How to make a service available at boot.
Can someone tell me how to make a service available at boot time via smf ? The question is for a generic service ( network/telnet for example ) and for a site one. Is it enough to enable it via svcadm ? Thanks.
-
Message Bundle for Arabic Text
Hi folks, I am trying to have a Arabic text in the message bundle properties file, however when i try to copy Arabic text, it shows up as junk characters. How do i go about resolving the same. Thanks.
-
Official Safari 4 Release Is Extremely Slow to Load Pages
Just installed the new Safari 4.0 (non-beta). Almost every page I bring up takes considerably longer to load. Graphics and audio are especially slow to load. Apple just touted how much faster this browser is supposed to be at WWDC. ??? Anyone else ex