Swing/AWT/SWT :: Getting Jlabel Icons To Change Size With Window Resize?

Feb 20, 2014

I'm trying to create a chess program in java swing, and for the board I'm using an 8 by 8 array of jlabels stuck inside a jpanel with a grid layout. I would like the board to change size when the window changes size, and the grid layout accomplishes this succesfully, until I add the actual icons to the jlabels. Then the board just stays a fixed size. Someone suggested I use their "Stretch Icon" class, found here:[URL] ...., so I tried initializing the icons using one of the constructors in the class (the one that takes an image name and a boolean value for whether or not you want the resisizing to be proportionate (to maintain the aspect ratio)). However, the same thing happened. The board appears, but it does not resisize. To attempt to fix this problem, I tried simplifying my code, reducing the program to two jlabels within the jpanel, for which I then tried to set the image in the same way. Here is my simplified code:

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;

[Code] ....

I'm misusing the stretch icon class, or just generally what's going wrong/how to fix it?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Getting Icons To Change Size With Window Resize

Jan 19, 2014

I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). URL...

So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implimentation of it, and how would I fix this?

View Replies View Related

Swing/AWT/SWT :: Getting Icons To Change Size With Window Resize?

Jan 16, 2014

I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). Someone suggested to me to use this custom stretch icon class, found here:

[URL] ....

So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implementation of it, and how would I fix this?

View Replies View Related

Swing/AWT/SWT :: JTextField Size Changes With JLabel Text Length

Nov 11, 2014

I want to create 3 JTextFields in a row with all being of equal size.But my first Text field gets so wide than the other two.After adding each component at a time and seeing what causes the problem I realized that if I type a long text for the JLabel that's when this problem occurs.If I reduce the length of the text in the JLabel JTextFields get into the sizes I want. Here's my code

import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class Calculator1 extends JFrame {
JTextField value1=new JTextField("0");
JTextField value2=new JTextField("0");

[Code] ....

How can I stop the JTextFields changing size when I change the JLabel label1's text length...

View Replies View Related

Swing/AWT/SWT :: Cannot Get ActionListener To Change JLabel Text

Apr 24, 2014

I am trying to write an application where if you click and hold down on 1 button and move the mouse to another button and release the text on the 2 buttons should be switched around.I have a print line so I can se the text are supposed to get switched around but it is just not happening in the GUI.

I attached all my code in case the flaw was to find somewhere else in the code, but the functionality I am working on is the lines 76 to 121.

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

[code]....

View Replies View Related

Swing/AWT/SWT :: Jscrollpane Not Shown Until Adjust Window Size With Mouse?

Nov 16, 2014

So for a test i have a small array set as a jlist which is the contents of my jscrollpane, and it appears as if nothing is there until i adjust the window size by dragging it out or in... whats going on?

Here is the full code

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

[Code] ...

View Replies View Related

Swing - WindowStateChanged Event Updates Window Size After It Completes

Feb 12, 2014

I have a JFrame where some elements (one, for now) have to be centered manually on the contentPane when resizing the window or changing the window state. Resizing event (componentResized) works fine but the windowStateChanged event is causing problems because it doesn't seem to "update" the contentPane's new size properly - it keeps the previous value although the window's size is obviously changed. This can be seen by simply printing the result of getSize called on contentPane.

Centering is done by programmatically changing the constraint of the component (using putConstraint, SpringLayout). The issue is that getWidth used in that method returns "wrong" values which results in an uncentered component. Maybe another listener is needed here?

Additional info: Eclipse with WindowBuilder, Linux Mint 15, Java 1.7

I know about SSCCE guidelines but I cannot make this particular example both ready to compile and short.For unknown reasons, I am unable to post the code example. I keep getting this - "Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words."

addWindowStateListener(new WindowStateListener()
{
// no "@Override" was generated but it is the same with it
public void windowStateChanged(WindowEvent e)
{
System.out.println("EVENT: " + contentPane.getSize() + ", "
+ getExtendedState() + ", " + e.getOldState()); // amusingly, states are actually correct - interchanging between 0 (Frame.NORMAL) and 6 (Frame.MAXIMIZED_BOTH) when I maximize and "unmaximize"
tfArrayPanelCenter();

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Make JLabel Hyperlink Change Depending On JTextField

Jul 30, 2014

This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.

public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Change Size Of Entire GUI?

Feb 4, 2015

I built a GUI and after testing it on various platforms I think I would like to make it bigger by a factor of 2.2 or so.

Is there an easy way to just enter the factor 2.2 and have the GUI change by that factor?

I have over 50 components in the GUI. Ideally each one would just enlarge by the factor including the fonts.

This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code.

View Replies View Related

Swing/AWT/SWT :: How To Change JFrame Size

Jan 14, 2015

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code].....

View Replies View Related

How To Change Fonts And Font Size In Swing

Feb 10, 2014

So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?

View Replies View Related

Resize Window To See Programs

Jan 21, 2014

Whenever I make something in Swing, I always need to resize the window for me to see the graphics on the window. I have been told to use the pack() method on it, which I have, but the problem with it is that it just sets the window to a minimal size, only displaying the x + and -.For one of the "games" I made, it at first didn't work until resize, then I added a repaint() after the constructor and it worked for me, but when my friends download it they cannot see it.

View Replies View Related

JavaFX 2.0 :: Drag Events Destroyed By Window Resize?

Jan 24, 2015

I've been having great success developing a drag-drop component for a JavaFX app, but I've run into an issue that has me completely stumped.
 
Specifically, I create a component that can be dragged around inside an anchor pane.  That anchorpane is nested in a split pane, which is nested in another anchor pane (the control's root element).
 
The issue can be described this way:
 
Case #1:  If I start the application as a small window, I can reposition the control by dragging it around the screen as I please.
Case #2: If I start the application and maximize the window, again, I can drag the control around the screen as I please.
Case #3: If I start the application, drag the control around a bit, then resize the window, the drag event handling breaks as follows:

1.  The control drag events will fire normally only within the bounds of the anchor pane's previous size.
2.  The mouse cursor's drag icon changes as I pass in or out of those bounds
 
I'm absolutely certain the anchorpane is resizing to match the parent window, otherwise Case #2 would not succeed.  I'm at a complete loss as to determine why the drag events don't fire within the bounds of the resized window after they've been fired within the bounds of it's previous size.
 
Understand the mechanism I'm using to establish the drag handling:  Once the controller is instantiated and added to the scene, an event listener on the class's parentProperty fires to attach the drag event handling to the parent node.
 
Previously, I was setting / clearing the drag handling on the parent node in the drag detection / drag dropped event handlers.  I had suspected that adding / removing drag events was causing the trouble and opted for this solution to ensure that the same event instance was being used each time.  Both methods have had the same result.
 
If you want to see the UI in action, here's a youtube link (it does not demonstrate the problem I'm having):
 
[URL]
 
Here's the code that I'm using, redacted for clarity:
 
public class FileSystemNode extends AnchorPane {
@FXML private AnchorPane fs_node_title;
private FileSystemType mFsType;
private Point2D mDragPoint;

[Code]....

View Replies View Related

ABV Calculator - Unable To Set JLabel Properly On Top Of Created Window

Dec 19, 2014

So I am working on an ABV calculator for some practice, and one problem I am running into is that I am unable to set a JLabel properly on the top of the window that is created. It will display the text with no problem, but only on one column. Is there a way to center a JLabel across 2 columns? The label I am working with is titleL.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class Beer_Calculator extends JFrame

[Code] .....

View Replies View Related

Display Image On JLabel Or JPanel With Respect Of Components Size?

Mar 27, 2015

i have very critical problem in my collage project i have try many code but still i cant solve this problem, i want to display image on jlabel or jpanel with respect of components size without use of drawimage method

View Replies View Related

How To Change JLabel Text By Clicking On JButton

Feb 25, 2015

Here's my coding so far...I want to be able to change what the JLabel says when clicking on one of the buttons for example : when clicking on UP i want it to say "Going Up!"...how do i do this?

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
 public class BorderLayoutJFrame extends JFrame {

[Code] .......

View Replies View Related

Change Text In JLabel When Button Pressed

Dec 4, 2014

Ok, so I am trying to learn about JFrames and JPanels. I have figured out buttons, layouts, etc. What im having trouble with is accessing the label object from the ButtonHandler class since it is static and I need my JLabel to be non-static so that it can change. Basically, I want JLabel to change to a pre-determined text string once a button is pressed. Here's what I have so far

package makewindow;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related

How To Make JLabel Hyperlink Change Depending On JTextField

Jul 30, 2014

This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.

public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

[Code] ....

View Replies View Related

Get ActionEvent When Change JFrame Size?

Apr 8, 2014

I wanted to make a program that would change the color of a circle when I click a button. The problem is that the circle also changes color when I manually change the size of the frame with my mouse. For some reason it trigers an ActionEvent, and i don't know why.

My code is the following:

Java Code: import java.awt.*;
import javax.swing.*;
public class MyFirstGui implements ActionListener {
JFrame frame;
public static void main(String[] args){

[code]....

View Replies View Related

Program To Change Colors Of A Shape In Other Window

Feb 13, 2015

I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemo {
//Global Variables
static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue .
static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .

[Code] ....

The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.

View Replies View Related

Swing/AWT/SWT :: Icons Should Drag Starting At Point Where Mouse Originally Clicked Down

Apr 23, 2014

I am working on a simple app that should emulate a desktop with some icons that you can drag around. I was instructed to use the MouseListener and MouseMotionListener. The icons should drag starting at the point where the mouse originally clicked down on it (ie not dragging from the top right corner).

I am drawing my icons to a jpanel, and I seem to be having two problems:The hitboxes are offThe icon is being dragged from the top right corner, despite having setup up a mouse offset at the beginning of the drag..Here are the relevant classes, the Desktop.draw() method is being called from my DrawPanel

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Desktop implements MouseListener, MouseMotionListener{
static DesktopIcon[] icons;

[code]...

View Replies View Related

Why Cannot Change Size Of TextField In Java For Calculator Application

Jan 13, 2014

package name;swing library found in javax called to use the graphical contents.

import javax.swing.*;
//creating the contents for the calculator
public class calc {
JButton btn1= new JButton("1 ");
JButton btn2= new JButton("2");
JButton btn3= new JButton("3");

[code]....

I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.

View Replies View Related

Swing/AWT/SWT :: Flickering On Resize

Jan 12, 2011

I need to create a program that draws a graph, but for now, all I have done is two lines: the X and Y axis. The program is designed in a way as to automatically resize the graph when the window is resized.

Is this code in some way extremely inefficient? I get TERRIBLE flickering when I resize the window. Is there something that will at least reduce the flickering?

mainApp.java:
import java.awt.*;
import javax.swing.*;
public class mainApp {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setVisible(true);

[Code] ....

I have added a screenshot that shows the window flickering.

View Replies View Related

Swing/AWT/SWT :: Resize Objects From ArrayList

Jan 10, 2014

I have a problem with my program. My aim is to display in a JPanel, 2 rectangles from an arraylist, and resize them by clicking. I want to give the user the ability to change the height of the rectangles (independently) by moving the top and/or bottom edges. There is errors in my code but where ? Netbeans underlines 2 lines (in bold).

My code:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Path2D;

[Code]....

View Replies View Related

Swing/AWT/SWT :: Auto Resize Components

Sep 5, 2014

I have swing UI designed and I want the components to resize when the frame is manually resized. The design is as shown in the fig Project UI.jpg

The panel 4 and panel 5 will change their contents according to the list item clicked. Panel 4 just has text area but panel 5 a panel with numerous components as label, combo box, text field,check box will be present.Now if the frame resizes, I won't all the components to resize according to the frame size.

View Replies View Related

Swing/AWT/SWT :: How To Resize Image Icon

Aug 15, 2001

Any way to resize an ImageIcon when placing it on a Button so that I don't have to physically rezize the image file?? I am writing an Application, not an applet, so the getImage method won't work.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved