Multiple JLists controlled by one Scroll Pane?
I'm trying to figure out a way of putting together a number of JLists within a single scroll pane. For example, on my PDA, to set the time there is one component that appears to be made up of 3 lists (hours, minutes, AM/PM) that are all controlled by one scrollbar. You highlight the element (hours, minutes, etc) and then scroll up or down to set it.
Is there a way to do that in Java?
Thanks!
sailor_geek wrote:
I'm trying to figure out a way of putting together a number of JLists within a single scroll pane. For example, on my PDA, to set the time there is one component that appears to be made up of 3 lists (hours, minutes, AM/PM) that are all controlled by one scrollbar. You highlight the element (hours, minutes, etc) and then scroll up or down to set it.So the list that scrolls is the one that's highlighted while the others don't change? Kind of like a table except that only one column scrolls with the scrollbar at a time? Or am I confused on this?
Is there a way to do that in Java?I think that there is, but (for me) it would take a bit of work. Let's see what the experts have to say.
Similar Messages
-
Multiple atv2 controlled by one computer
I hope this makes sense.
I am working on a project and require some information. I have 10 LCD displays that are used a a public broadcast system - to display announcements important notices (for a school). Currently we use PowerPoint to do this but when we upgraded the screens no thought was given to HD requirements of the LCD screens. As a result the slide being generated are blurred due to the video card output being low res.
Atv2 is a potential solution as it will broadcast media in HD using existing infrastructure. I was hoping to use the apple tv 2 to broadcast a keynote presentation (as yet not available) and have managed to export keynote slides as jpegs and put them into slide show albums in Iphoto. The slides show up very nicely but each time I update or add a new slide I have to go to each apple tv and have it "re sync" with the computer to update the photo file. This must been done individually at each apple tv (so essentially 10 times). So my questions are
Does anybody know if I can control 10 atvs from iTunes on an iMac to start up a slideshow rather than going to each atv station to "recache" the photo library? Alternatively can I start a video (again on multiple atvs) from the computer station rather than going to each atv to start the stream with the remote?I'm sure that you will be able to find a way to make this work.
I haven't looked at putting together slideshows and playing them on the atv, but I believe that it can be done. I'm not sure how it works and I think it is controlled from the individual atv.
Probably the best solution would be to make it into a video and then, if Airplay does what I believe it should next month then you should be able to use that.
It can be controlled from a remote on iPhone or iPad and you can control which sets will get the video.
The only concern I would have is whether ten streams would clog your network, but I'm not sure how Airplay works with this (whether it sends out 10 individual streams or one stream to multiple devices. It would still take up quite a bit of bandwidth though.
HJope that helps. -
Hello,
I have to scroll panes and movie clips in the one scroll
pane while the other is blank. I wanted the user to be able to drag
the movie clip out of the one scroll pane and drop it into the
blank one. Any ideas? I'm totally lost on this one.
Thank YouHi Sarojamaly,
According to your description, when you create a Data Source View in BIDS/SSDT, you can't see the tables in the pane. Right?
In this scenario, when creating data source, please make sure you select a correct data provider. For example, it you connect to SQL Server database, you should use
Native OLE DB\SQL Server Native Client. Then please test your connection to the data source.
If the tables still can't be displayed, please make sure you select proper database and the check tables existence in the database.
Best Regards,
Simon Hou
TechNet Community Support -
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. -
Controlling movieclip playback in Scroll Pane Component
Hi all,
In a CBT Cafe Tutorial (
http://www.cbtcafe.com/index.htm)
Flash Scrollpane Component & Load Movie Video Tutorial,
there is a controler at the bottom of the Flash Movie to Stop,
Start, Pause and Play the content. I would like to know how this is
done.No, I had no reply and eventually wrote my own scroll pane
solution which allows me to directly modify the pane's content with
ActionScript and update the scroll bar to reflect any change in the
content's size. I'm puzzled by the help file's example in
ScrollPane.refreshPane() because it describes a senario where:
"for example, you've loaded a form into a scroll pane and an
input property (for example, a text field) has been changed by
ActionScript. In this case, you would call refreshPane() to reload
the same form with the new values for the input properties."
Which implies that you can use ActionScript to change the
content then reload it. The help file on ScrollPane.contentPath is
not very clear about what content can be used but appears to say
that the only content types allowed are: a SWF or JPEG loaded via
its URL or a symbol in the current library. I don't see how you
could use ActionScript to change any of these. I've tried
specifying an on-stage instance as the content but that
fails. -
Multiple mitigating controls assigned to one risk
Hello experts. We are using GRC compliance calibrator 5.3. We are just starting to implement mitigating controls. The problem we have is we have multiple mitigating controls per risk. Some risks have one control and some have two or three. When we run our risk analysis the resulting report only shows the first mitigating control it finds.
Just wondering if anyone else has this situation. I wanted to check here before I created a message with SAP.
Thanks
DaveDave,
I think this is how the functionality is. You will have to open a CSS message with SAP.
Regards,
Alpesh -
One Filter Pane to filter multiple analysis
Hi everyone,
I have a questions related to WAD7.0 and need your help:
How to use one Filter Pane to filter multiple Alalysis/querys on one web page?
Thank you very much in advance,
Jin FredaWe are on SP13 now and i just checked this functionality. Can't find it. I think this new parameter has not been included in the filter pane.
Can someone confirm this?
Or is the problem in front of the screen?
Thanks
Michael -
Hello. I added custom http response headers to my SP site web config file as follows:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type,Authorization" />
</customHeaders>
</httpProtocol>
When I try to call any web service, i get these headers two times each:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Transfer-Encoding: chunked
Content-Type: application/atom+xml;type=entry;charset=utf-8
Expires: Sat, 01 Mar 2014 19:11:37 GMT
Last-Modified: Sun, 16 Mar 2014 19:11:37 GMT
ETag: "3"
X-SharePointHealthScore: 0
SPClientServiceRequestDuration: 20
SPRequestGuid: b4e77d9c-bfc3-a050-493a-ca5d251d1a72
request-id: b4e77d9c-bfc3-a050-493a-ca5d251d1a72
X-FRAME-OPTIONS: SAMEORIGIN
Persistent-Auth: true
Access-Control-Allow-Methods: POST,GET,OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type,Authorization
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Access-Control-Allow-Methods: POST,GET,OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type,Authorization
MicrosoftSharePointTeamServices: 15.0.0.4569
Date: Sun, 16 Mar 2014 19:11:37 GMT
and that gives me error from ajax: The 'Access-Control-Allow-Origin'
header contains multiple values '*, *', but only one is allowed. Origin 'null' is therefore not allowed access.
The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
Origin 'null' is therefore not allowed access.
Any idea???Hi Ann,
Please check whether there are duplicate custom headers in your code.
Similar issue for your reference:
http://social.msdn.microsoft.com/Forums/office/en-US/b79b75f4-b46b-46ae-ae29-17a352b6b90b/custom-http-response-headers-for-sp-2013-shown-2-times?forum=sharepointdevelopment
Regards,
Rebecca Tu
TechNet Community Support -
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). -
Scroll pane can't align it's content
When a Node(group fro example) is added into a scroll pane, the scroll pane automatically align the node to the upper left corner of the scroll pane's content area. How can i customize the Node's alignment(the middle center eg) in the scroll pane. When the Node's size is scaled and larger than the scroll pane's size the scroll pane's scroll bar appears, and if the Node's size shrinks and it's size becomes smaller than the scroll pane's then the Node is aligned to the middle center. it seems don't take affect if i override the scroll pane's layoutChildren method and set layoutX and layoutY property of the Node.
If any one can give me some clue?
thanksScrollPanes are somewhat tricky to use. They don't align content, you need to use layout managers to do that or you need to layout yourself with shapes in groups using absolute co-ordinates and/or translations. The ScrollPane defines it's own viewport related coordinates and you need to layout your content within that viewport.
How can i customize the Node's alignment(the middle center eg) in the scroll pane.Get the layoutBoundsInParent of the node, get the viewportBounds of the scrollpane and perform the translation of the node such that the center of the node is in the center of the viewportBounds (will require a little bit of basic maths to do this) by adding listeners on each property.
When the Node's size is scaled and larger than the scroll pane's size the scroll pane's scroll bar appears, and if the Node's size shrinks and it's size becomes smaller than the scroll pane's then the Node is aligned to the middle center.Similar to above, just work with those properties.
Not exactly a direct answer to your question, but you could try playing around with the following code if you like Saludon. It is something I wrote to learn about JavaFX's layoutbounds system. Resizing the scene and toggling items on and off will allow you to see the scroll pane. The view bounds listeners show you the properties you are interested in to achieve the effect you want.
import javafx.application.Application;
import javafx.beans.value.*;
import javafx.event.*;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
public class LayoutBoundsScrollableAnchorPane extends Application {
// define some controls.
final ToggleButton stroke = new ToggleButton("Add Border");
final ToggleButton effect = new ToggleButton("Add Effect");
final ToggleButton translate = new ToggleButton("Translate");
final ToggleButton rotate = new ToggleButton("Rotate");
final ToggleButton scale = new ToggleButton("Scale");
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) throws Exception {
// create a square to be acted on by the controls.
final Rectangle square = new Rectangle(20, 30, 100, 100); //square.setFill(Color.DARKGREEN);
square.setStyle("-fx-fill: linear-gradient(to right, darkgreen, forestgreen)");
// show the effect of a stroke.
stroke.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
if (stroke.isSelected()) {
square.setStroke(Color.FIREBRICK); square.setStrokeWidth(10); square.setStrokeType(StrokeType.OUTSIDE);
} else {
square.setStroke(null); square.setStrokeWidth(0.0); square.setStrokeType(null);
reportBounds(square);
// show the effect of an effect.
effect.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
if (effect.isSelected()) {
square.setEffect(new DropShadow());
} else {
square.setEffect(null);
reportBounds(square);
// show the effect of a translation.
translate.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
if (translate.isSelected()) {
square.setTranslateX(100);
square.setTranslateY(60);
} else {
square.setTranslateX(0);
square.setTranslateY(0);
reportBounds(square);
// show the effect of a rotation.
rotate.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
if (rotate.isSelected()) {
square.setRotate(45);
} else {
square.setRotate(0);
reportBounds(square);
// show the effect of a scale.
scale.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
if (scale.isSelected()) {
square.setScaleX(2);
square.setScaleY(2);
} else {
square.setScaleX(1);
square.setScaleY(1);
reportBounds(square);
// layout the scene.
final AnchorPane anchorPane = new AnchorPane();
AnchorPane.setTopAnchor(square, 0.0);
AnchorPane.setLeftAnchor(square, 0.0);
anchorPane.setStyle("-fx-background-color: cornsilk;");
anchorPane.getChildren().add(square);
// add a scrollpane and size it's content to fit the pane (if it can).
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(anchorPane);
square.boundsInParentProperty().addListener(new ChangeListener<Bounds>() {
@Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldBounds, Bounds newBounds) {
anchorPane.setPrefSize(Math.max(newBounds.getMaxX(), scrollPane.getViewportBounds().getWidth()), Math.max(newBounds.getMaxY(), scrollPane.getViewportBounds().getHeight()));
scrollPane.viewportBoundsProperty().addListener(
new ChangeListener<Bounds>() {
@Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldBounds, Bounds newBounds) {
anchorPane.setPrefSize(Math.max(square.getBoundsInParent().getMaxX(), newBounds.getWidth()), Math.max(square.getBoundsInParent().getMaxY(), newBounds.getHeight()));
// layout the scene.
VBox controlPane = new VBox(10);
controlPane.setStyle("-fx-background-color: linear-gradient(to bottom, gainsboro, silver); -fx-padding: 10;");
controlPane.getChildren().addAll(
HBoxBuilder.create().spacing(10).children(stroke, effect).build(),
HBoxBuilder.create().spacing(10).fillHeight(false).children(translate, rotate, scale).build()
VBox layout = new VBox();
VBox.setVgrow(scrollPane, Priority.ALWAYS);
layout.getChildren().addAll(scrollPane, controlPane);
// show the scene.
final Scene scene = new Scene(layout, 300, 300);
stage.setScene(scene);
stage.show();
reportBounds(square);
/** output the squares bounds. */
private void reportBounds(final Node n) {
StringBuilder description = new StringBuilder();
if (stroke.isSelected()) description.append("Stroke 10 : ");
if (effect.isSelected()) description.append("Dropshadow Effect : ");
if (translate.isSelected()) description.append("Translated 100, 60 : ");
if (rotate.isSelected()) description.append("Rotated 45 degrees : ");
if (scale.isSelected()) description.append("Scale 2 : ");
if (description.length() == 0) description.append("Unchanged : ");
System.out.println(description.toString());
System.out.println("Layout Bounds: " + n.getLayoutBounds());
System.out.println("Bounds In Local: " + n.getBoundsInLocal());
System.out.println("Bounds In Parent: " + n.getBoundsInParent());
System.out.println();
} -
Pulling text from a .txt to a scroll pane or text area
Hi-
I'm sure there's a way to do this, but I'm not exactly fluent in ActionScript.
Basically, my whole website's going to be in Flash, but I want to be able to update one page (sort of a news/blog page) without having to edit the Flash file every time. I'm assuming the easiest way to do this would be to set up either a scroll pane or a text box and pull the text in from a .txt file (if there's a better way, please let me know). That way I could continue to add on to the .txt file, and Flash would always pull in the current version.
So, my issues are:
1. I have no idea where to start with the code for something like that. Is it a LoadVar? Do I physically put a scroll pane or a text area in the frame and put the action on that, or do I put the action on the frame and have it call up a text area component?
2. Will the text scroll automatically, or is that something else I would have to add in? I plan on adding to this text file for awhile, so it could end up being a lot of text over time.
3. Would I be able to format the text in the .txt at all? For instance, if I hit enter to put in a paragraph break, would that register once it's pulled into Flash, or would I have to put in an html paragraph break or something? That may be a dumb question, but as I said, I'm not exactly fluent in ActionScript (or any other programming language for that matter).
Any help is definitely appreciated!
Thanks!
-GeoffI recommend you use an xml file rather than a text file for storing your content. The main reason being that it tends to make thing more easily organizable, as well as easier to differentiate things like titles, contents, links, images, etc.
You could start off using a TextArea component if you want, just to keep things simple. If you want to format things you can use the htmlText property rather than the text proiperty when assigning your content. That will allow you more control of the presentation.
If you want to take the xml approach, you should search Google for "AS# XML tutorial" where you substitute whatever version you plan to use for the "#". If you plan to use AS3, there is a good tutorial here: http://www.gotoandlearn.com/play?id=64 -
FCP 10.1.3 multiple graphic images into one frame
Hi - How do I put multiple graphic images into one frame? - so it kind of looks like a video wall - except these are still images. I can do it manually but it's not precise. Anyone found a way other than this? Thanks.
Here is my quick and dirty generator called "9 Pictures": https://www.dropbox.com/s/92c536wgesh2yzj/9%20Pictures.zip?dl=0
To install it, unzip the file and place the folder inside /Users/yourname/Movies/Motion Templates/Generators
It will look like this in FCP X. You just have to click each drop zone icon in the inspector and then select the desired clip from the browser. Use the Pan and Scale controls in the inspector to select which part of each image you want to use. Note: this was done in the hope that it may be helpful, but it is no more than a quick thing. You can also control-click the generator in the generator browser and choose open in motion (if you have it) to see how it was done and to modify it. -
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! -
Can't get image in the scroll pane.
I have written a program to show image in scrollpane. Image has put in the same directory of program. But Still I am not getting image in the scroll pane.
Please have a look into program and let me know where I commit mistake.
package com.lko.fx.controls;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
* @author Upadhyay
public class ScrollPaneFx extends Application{
private Scene scene;
private Group root;
* @param args
public static void main(String args[]){
launch(args);
* @param primaryStage
* @throws Exception
@Override
public void start(Stage primaryStage) throws Exception {
root = new Group();
scene = new Scene(root, 300, 240, Color.WHITE);
scrollPaneDemo();
primaryStage.setTitle("ScrollPane Demo");
primaryStage.setScene(scene);
primaryStage.show();
private void scrollPaneDemo() {
ImageView imgView = new ImageView(new Image(this.getClass().getResourceAsStream("img.png")));
ScrollPane spane = new ScrollPane();
spane.setContent(imgView);
root.getChildren().add(spane);
Thanks in Advance!
Regards,
HimanshuOk, check whether it is the image loading or something else in your code. Is the result of the getClass().getResource() method null or not null? Once we know that we know which direction to hunt in.
Also I assume you are running in an IDE. Which one? Make sure the build picks up images. Maven for example won't pick them up from your 'src/java' directory. -
Could someone please tell me why in the following code the Scroll Pane does not appear? The code refers to two other classes I didn't include here although I've added comments to explain how they're used.
Thanks very much.
public class VPA extends JPanel implements ListSelectionListener {
static DB2Connect vpaDB2connect = null;
JPanel contentPanel;
JPanel subPanel;
JList listOfData;
DataList dataList;
VPAsql vpaSQL;
public VPA() {
vpaDB2connect = new DB2Connect(); // a DB2 database connection
vpaDB2connect.makeConnection();
subPanel = new JPanel();
subPanel.setLayout(new BoxLayout(subPanel,BoxLayout.Y_AXIS));
subPanel.add(Box.createRigidArea(new Dimension(0,5)));
dataList = new DataList(vpaDB2connect); //returns a list of data
listOfData = dataList.getList(); // listOfData is a JList
listOfData.addListSelectionListener(this);
JScrollPane scrollPane = new JScrollPane(listOfData);
scrollPane.setPreferredSize(new Dimension(250,80));
scrollPane.setMinimumSize(new Dimension(250,80));
scrollPane.setAlignmentX(LEFT_ALIGNMENT);
subPanel.add(listOfData);
subPanel.add(scrollPane);
contentPanel = new JPanel();
contentPanel.add(subPanel,BorderLayout.CENTER);
public void valueChanged(ListSelectionEvent e) {}
public static void main(String[] args) {
VPA vpa = new VPA();
JFrame frame = new JFrame("VPA");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.setContentPane(vpa.contentPanel);
frame.pack();
frame.setVisible(true);
}The suggested solution about adding the following line
to my code does not make any difference.
frame.setContentPane(vpa);
I'm still looking for an answer on why the Scroll Pane
is not being displayed. If you havent fixed the prob then why did you give Duke Dollars to someone? anyway i don't see the probem Try this out:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VPA extends JPanel
JPanel contentPanel;
JPanel subPanel;
JList listOfData;
public VPA()
String[] list = {"one", "two", "three", "four", "five", "Six", "seven", "eight", "nine", "ten"};
listOfData = new JList(list);
subPanel = new JPanel();
subPanel.setLayout(new BoxLayout(subPanel,BoxLayout.Y_AXIS));
subPanel.add(Box.createRigidArea(new Dimension(0,5)));
JScrollPane scrollPane = new JScrollPane(listOfData);
scrollPane.setPreferredSize(new Dimension(250,80));
scrollPane.setMinimumSize(new Dimension(250,80));
scrollPane.setAlignmentX(LEFT_ALIGNMENT);
subPanel.setBackground(Color.yellow);// to see where subPanel is in the layout
subPanel.add(new JTextField());
subPanel.add(scrollPane);
contentPanel = new JPanel();
contentPanel.setBackground(Color.orange);// to see where the contentPanel is in the layout
contentPanel.add(subPanel,BorderLayout.CENTER);
public static void main(String[] args)
VPA vpa = new VPA();
JFrame frame = new JFrame("VPA");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.setContentPane(vpa.contentPanel);
frame.pack();
frame.setVisible(true);
Maybe you are looking for
-
Acrobat 9 Pro Cannot select image and overlapping text
I want to copy a section of a newspaper page that includes both text and graphics and keep it looking the same. When I draw the select box around the section using the mouse the box just disappears when I let go of the mouse button. I already did the
-
Display Table contents using HTMLB...Urgent Help Plz...
Hello All, Im working on EP SP14 and SQL Server 2000. I have successfully established database connection. I want to know <b>how can I display Table contents using TableViewModel in HTMLB</b>. Please help. Its urgent. Awaiting Reply. Thanks in advanc
-
I need to reboot after closing screen
When I leave my MacBook on and just close the screen and do something else and come back and open it, sometimes is does not come back to life and I have to reboot. I think this should not be happening, because most of the time it works just fine. My
-
What's happened to downloadable help pdf for Premiere?
How do I download a help pdf for Premiere? When I open the help topics page, there is message bottom right which says that this info can be downloaded. But how?*
-
Reg : Hierarchy extraction from Source
Hello Friends, I have an issue with Hiearchy Extraction. I am trying to Load 0WBS_ELEMT ( Hiearchy) data (Full Update) for the first time.Its displaying the following error.(Its extracted from SAP R/3) Diagnosis The hierarchy level of the parent