I'm trying to fit my Content to my scrollPane. However, I cannot scroll until the end of the content. It work if resize the whole pane to my PC screen (1920,1080), however it can't fit for my laptop resolution (1366,768).
This is what happen
///////////////////////////////////////////////////CENTER SIDE OF THE PANE///////////////////////////////////////////////////
//Scroll Pane for insert centerbox in it
ScrollPane scroll = new ScrollPane();
//Grid pane for center box
GridPane centerbox= new GridPane();
centerbox.setHgap(15);
centerbox.setVgap(30);
//Input picture
javafx.scene.image.Image img = new
javafx.scene.image.Image(getClass().getResource("arcade.jpg").toExternalForm());
ImageView imgv1 = new ImageView(img);
imgv1.setFitHeight(150);
imgv1.setFitWidth(150);
imgv1.setVisible(true);
Image img2 = new Image(getClass().getResource("Bowling.jpg").toExternalForm());
ImageView imgv2 = new ImageView(img2);
imgv2.setFitHeight(150);
imgv2.setFitWidth(150);
imgv2.setVisible(true);
Image img3 = new Image(getClass().getResource("cc.jpg").toExternalForm());
ImageView imgv3 = new ImageView(img3);
imgv3.setFitHeight(150);
imgv3.setFitWidth(150);
imgv3.setVisible(true);
Image img4 = new Image(getClass().getResource("circus.jpg").toExternalForm());
ImageView imgv4 = new ImageView(img4);
imgv4.setFitHeight(150);
imgv4.setFitWidth(150);
imgv4.setVisible(true);
Image img5= new Image(getClass().getResource("karaoke.jpg").toExternalForm());
ImageView imgv5 = new ImageView(img5);
imgv5.setFitHeight(150);
imgv5.setFitWidth(150);
imgv5.setVisible(true);
Image img6= new Image(getClass().getResource("kidzania.jpg").toExternalForm());
ImageView imgv6 = new ImageView(img6);
imgv6.setFitHeight(150);
imgv6.setFitWidth(150);
imgv6.setVisible(true);
Image img7= new Image(getClass().getResource("skatepark.jpg").toExternalForm());
ImageView imgv7 = new ImageView(img7);
imgv7.setFitHeight(150);
imgv7.setFitWidth(150);
imgv7.setVisible(true);
//////////////////////////////////////////////COMBINING ALL THE PANE TOGETHER////////////////////////////////////////////////////////
//Place Node on Pane(1)
centerbox.add(imgv1,0,0);
Button buy = new Button("Reserve");
Label l1 = new Label();
l1.setText("'Arcade-ium'\n\n\nAt Arcade-ium, you can enjoy a lot of classic and modern arcade game.\nWe assure you your satisfaction");
l1.setFont(Font.font("Helvetica",FontWeight.BOLD,20));
centerbox.add(buy,2,0);
centerbox.add(l1,1,0);
//Event Handler to change scene to reservepage
buy.setOnAction(e->{
Stage stg = (Stage)buy.getScene().getWindow();
stg.setScene(rp.getScene1());
});
///Repeat until 7 node
//Place Node on Pane(7)
centerbox.add(imgv7,0,6);
Button buy6 = new Button("Reserve");
Label l7 = new Label();
l7.setText("'xTremePark'\n\nxTremePark was built in 2011. We have a lot of facilities here to facilitate our youngster who\nlove to take the risk and go beyond.");
l7.setFont((Font.font("helvetica",FontWeight.BOLD,20)));
centerbox.add(l7,1,6);
centerbox.add(buy6,2,6);
//Event Handler to change scene to reservepage
buy6.setOnAction(e->{
Stage stg = (Stage)buy6.getScene().getWindow();
stg.setScene(rp.getScene7());
});
//Formatting the pane
scroll.setContent(centerbox);
//Im using borderpane for the whole scene. And Im going to insert the scrollpane into the center.
I cannot seem to scroll until the end my content when i run the program. I tried to use .setMinHeight() and .setPrefHeight().
but nothings work. So is there any way for me to set how much the scroller would scroll in my scrollpane?
Image 1
Related
In the code it is pretty easy:
// Clip
Rectangle rect = new Rectangle(168, 168);
rect.setArcHeight(30);
rect.setArcWidth(30);
rect.setEffect(new Reflection());
imageView.setClip(rect); //where imageView is an ImageView
I am trying to do it using SceneBuilder but i don't know
how..Any help will be appreciated.
If i well understood you are trying to populate a node (like a box or box or a pane or whatever you want)with your object rectangle, i think it's not possible doing it from the Scene Builder, you must do it from the code.
If you want to do it you have add it to a subScene i think!
PerspectiveCamera camera = new PerspectiveCamera();
ImageView imageview = new ImageView();
Rectangle rect = new Rectangle(168, 168);
rect.setArcHeight(30);
rect.setArcWidth(30);
rect.setEffect(new Reflection());
imageview.setClip(rect);
Group g = new Group(imageview);
SubScene subSceneInsertion = new SubScene(g, 919, 600, true, SceneAntialiasing.BALANCED);
subSceneInsertion.setFill(Color.DARKSLATEGREY);//yourcolour
subSceneInsertion.setCamera(camera);
Group groupForSubScene = new Group(subSceneInsertion);
groupForSubScene.autoSizeChildrenProperty().setValue(Boolean.TRUE);
groupForSubScene.setAutoSizeChildren(true);
hBoxForRectangle.getChildren().add(groupForSubScene);
I am trying to give my interface a new function, but I have encountered some obstacles. I want to enlarge image on JLabel when mouseEnters.
Here is how my JLabels looks:
int sacle = 50 //Size of my JLabel Icon
int zoom = 10 // How much the icon should enlarge
imageIcon = new ImageIcon(new ImageIcon(myClass.class.getResource(Picture))
.getImage().getScaledInstance(scale, scale, Image.SCALE_SMOOTH));
JLabel stackIsGreat = new JLabel();
stackIsGreat.setIcon(imageIcon);
//and I add multiple of such JLabels`
And the code goes on and on. I wanted to creat a function and add it to mouseListener, so all will behave the same. I wanted to achive that with:
//inside external method
activeLabel = (javax.swing.JLabel)(e.getSource());
ImageIcon temp = (ImageIcon) activeLabel.getIcon();
But there is no way I know I could get use of this, because java says I need Image to create my enlarged ImageIcon
ImageIcon enlarged = new ImageIcon((Image).getScaledInstance(scale + zoom, scale + zoom, Image.SCALE_SMOOTH))
How can I retrive the image used to crate the JLabel from code.
Any help would be appreciated.
I want to enlarge image on JLabel when mouseEnters.
Instead of creating your own MouseListener you could use a JButton to give you the rollover effect:
Something like:
JButton button = new JButton(...);
button.setBorderPainted( false );
ImageIcon icon = (ImageIcon)button.getIcon();
Image image = icon.getImage();
Image scaled = image.getScaledImage(...);
button.setRolloverIcon( new ImageIcon( scaled ) );
I'm new to java.
I want to make my image to act as the button in my project. Like the windows phone tile. My frame background is black. And I arranged 6 buttons. I also added an image but it comes with some white spaces around the image as borders. Here is the code i used:
ImageIcon image = new ImageIcon(getClass().getResource("yellowimage.png");
JButton button = new JButton(image);
I dont want those empty spaces. I just want the button to be exactly the image and wanted to type "click me" over the button. How can I do this ?
Try this:
JButton button = new JButton(image);
button.setContentAreaFilled(false);
button.setBorder(null);
You can also change the button image when it is pressed with:
button.setPressedIcon(pressedIcon);
You can try this to make JButton with an image.
Icon yourIcon = new ImageIcon("yourFile.gif");
JButton button2 = new JButton(yourIcon);
You can minimize the border around the image with setMargin();
ImageIcon image = new ImageIcon(getClass().getResource("yellowimage.png");
JButton button = new JButton(image);
button.setMargin(new Insets(1, 1, 1, 1));
Try this..
JButton button = new JButton();
ImageIcon icon = new ImageIcon(
ClassName.class.getResource("image.png"));
button.setIcon(icon);
button.setBackground(new Color(0,0,0,0));
button.setBorderPainted(false);
can we create 2 content panels in north widget.
BorderLayoutContainer con = new BorderLayoutContainer();
ContentPanel cp = new ContentPanel();
VerticalLayoutContainer logoLayout = new VerticalLayoutContainer();
BorderLayoutData d = new BorderLayoutData(.20);
d.setMargins(new Margins());
Image logo = new Image("/IMAGES/Logo.png");
logoLayout.add(logo);
cp.add(logoLayout);
cp.setHeaderVisible(false);
con.setNorthWidget(cp, d);
please suggest me how to create two content panels.
Basically what I need to do is - please look into the image and let me know what I can do for that
You create your two panels within a single panel, and then assign that single panel to NORTH. Remember that your overall layout can be created from nested layouts.
ContentPanel cp = new ContentPanel();
JPanel panelA = new JPanel();
JPanel panelB = new JPanel();
JPanel panelBig = new JPanel();
panelBig.add(panelA);
panelBig.add(panelB);
cp.add(panelBig, BorderLayout.NORTH);
I think you can probably work out the rest of the details on your own.
I am trying to do a fairly basic swing GUI where a user can enter a url, choose a local file location etc. I am using multiple layout managers including boxlayout, borderlayout and flowlayout. The code is below.
My problem is that some of the components are moving around when the user puts text into the optionsTxt jtextarea. Anyone know where I should start to stop this happening?
Setup menu bar
JButton menu_File = new JButton("File");
JButton menu_Edit = new JButton("Edit");
JToolBar toolBar = new JToolBar();
toolBar.add(menu_File);
toolBar.add(menu_Edit);
//Setup options area
JPanel options = new JPanel();
options.setBorder(BorderFactory.createTitledBorder("Options"));
BoxLayout layout_Options = new BoxLayout(options, BoxLayout.Y_AXIS);
options.setLayout(layout_Options);
JLabel optionsLblURL = new JLabel("Enter URL:");
optionsTxtUrl = new JTextArea(1,15);
JLabel chooseDestLbl = new JLabel("Choose save location:");
chooseDest = new JButton("Browse");
chooseDest.addActionListener(this);
options.add(optionsLblURL);
options.add(optionsTxtUrl);
options.add(chooseDestLbl);
options.add(chooseDest);
//Setup launch area
JPanel launch = new JPanel();
launch.setBorder(BorderFactory.createTitledBorder("Launch"));
launchBtnStart = new JButton("Start Download");
launchBtnStart.setVerticalAlignment(SwingConstants.CENTER);
launchBtnStart.setHorizontalAlignment(SwingConstants.CENTER);
launchBtnStart.addActionListener(this);
launch.add(launchBtnStart);
//Setup reporting area
JPanel logging = new JPanel();
logging.setBorder(BorderFactory.createTitledBorder("Log"));
BoxLayout layout_Logging = new BoxLayout(logging, BoxLayout.Y_AXIS);
logging.setLayout(layout_Logging);
JTextArea loggingTxt = new JTextArea(3,10);
loggingTxt.setEditable(false);
logging.add(pb);
logging.add(loggingTxt);
//Add components to window
BorderLayout borderLayout = new BorderLayout();
setLayout(borderLayout);
add("North", toolBar);
add("West", options);
add("East", launch);
add("South", logging);
setVisible(true);
"My problem is that some of the components are moving around when the user puts text into the optionsTxt jtextarea. Anyone know where I should start to stop this happening?"
Start by putting your JTextArea in a ScrollPane and setLineWrap(true) and setWrapStyleWord(true). You may want to consider doing this with both JTextAreas you have
JTextArea optionsTxtUrl = new JTextArea(1,15);
optionsTxtUrl.setLineWrap(true);
optionsTxtUrl.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(optionsTxtUrl);
options.add(scroll); // take out options.add(optionsTxtUrl);
This will make your lines wrap when they reach the right edge of the text area
public void setWrapStyleWord(boolean word) - Sets the style of wrapping used if the text area is wrapping lines. If set to true the lines will be wrapped at word boundaries (whitespace) if they are too long to fit within the allocated width. If set to false, the lines will be wrapped at character boundaries. By default this property is false.
public void setLineWrap(boolean wrap) - Sets the line-wrapping policy of the text area. If set to true the lines will be wrapped if they are too long to fit within the allocated width. If set to false, the lines will always be unwrapped. A PropertyChange event ("lineWrap") is fired when the policy is changed. By default this property is false.
If this doesn't solve your problem, you should edit your post with a Minimal, Complete, Tested and Readable example so we can test out your problem.