jlabel

Split image into clickable regions

一曲冷凌霜 提交于 2019-11-29 07:54:47
Is there any way to split an image to region (right now it's JLabel but I can change it if necessary)? I use swing in my program and I have an image (square for this example) with some triangles, stars and trapezoids inside it (it can be JPG, PNG, etc). The idea is that the user will click inside one of those shapes and then I will put another small icon on top of the area the user clicked. The user can click on multiple areas but at the end of the day, I need to know which shapes were clicked. Seems possible anyone? David Kroukamp Have a look at what I have made: This is the image I used for

How do I present text vertically in a JLabel ? (Java 1.6)

允我心安 提交于 2019-11-29 06:33:18
I'm looking to have text display vertically, first letter at the bottom, last letter at the top, within a JLabel. Is this possible? Arthur Thomas I found this page: http://www.java2s.com/Tutorial/Java/0240__Swing/VerticalLabelUI.htm when I needed to do that. I don't know if you want the letters 'standing' on each other or all rotated on their side. /* * The contents of this file are subject to the Sapient Public License * Version 1.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://carbon.sf.net/License.html. *

ActionListener for JLabel

≡放荡痞女 提交于 2019-11-29 02:20:43
I want to learn how to write an ActionListener for JLabel . I want to make a label that open a new frame for user when user clicks the label. Maybe MouseListener can work but I do not know how to make it. I recommend using a JTextField rather than a JLabel for this use. Being based on a component designed to be focusable, it allows an ActionListener and looks and feels more like an HTML link. E.G. That is how it appears when the mouse is hovering over the first link. LinkLabel /* License - LGPL LinkLabel Using the Desktop Class There are a lot of link labels. This one uses the Java 1.6+

Align text in JLabel to the right

冷暖自知 提交于 2019-11-29 02:06:36
问题 I have a JPanel with some JLabel added with the add() method of JPanel. I want to align the JLabel to the right like the image below but I don't know how to do that. Any Idea? Thanks! 回答1: This can be done in two ways. JLabel Horizontal Alignment You can use the JLabel constructor: JLabel(String text, int horizontalAlignment) To align to the right: JLabel label = new JLabel("Telephone", SwingConstants.RIGHT); JLabel also has setHorizontalAlignment : label.setHorizontalAlignment(SwingConstants

for loop issue when cycling through images for Jlabel with button click

梦想的初衷 提交于 2019-11-28 14:42:08
in a java aplication I have a Jlabel which i want to assign a new image to every time i click a button, using a for loop i can get it to just display the last image skipping all in between images, i know there is a error in my logic here maybe i should not be using a for loop?? any advice private String imageList[]; ImageIcon image; imageList = new String[] {"src\\Tour_Eiffel_Wikimedia_Commons.jpg","src\\Ben.jpg", "src\\Rio.jpg", "src\\Liberty.jpg", "src\\Pyramid.jpg"}; //constructor setting first image to display on load public GeographyGameGUI() { image = new ImageIcon(imageList[0]);

JLabel won't show with JPanel.setLayout(null). Why?

我的梦境 提交于 2019-11-28 14:21:08
I want to show many different labels over a map, so I'm using null layout in my panel, and calling setLocation for each label. For some reason, though, the labels don't show. If I remove the pan.setLayout(null), then the label appears in the top-center of the panel. Why isn't null layout working with setPosition? package mapa; import java.awt.*; import javax.swing.*; public class Mapa extends JFrame { private static JPanel pan; private static JLabel lab; public Mapa() { } private static void createAndShowGUI() { Mapa frame = new Mapa(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); lab

Changing a JLabel's Value from a JSlider's Value

爱⌒轻易说出口 提交于 2019-11-28 14:07:05
I have a single JPanel that contains a JSlider and a JLabel. I want to configure it so that when the JSlider's value is being changed by the user, that new value is reflected by the JLabel. I understand that I can fire ChangeEvents with the Slider, but I don't know how to add a ChangeListener to the JLabel. Here's a snippet of my code. scaleSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { int currentTime = ((JSlider)event.getSource()).getValue(); doSomething(currentTime); fireStateChanged(event); } JLabel timeValue = new JLabel("Time: " +

JPanel positioned incorrectly

夙愿已清 提交于 2019-11-28 13:06:27
问题 I've made a game in Java, where you're supposed to guess a random-generated int, between 1-100. If you guess too low, a textfield will be filled with a text that says, "too low" but in Swedish. Same if you guess too high. The problem occurs when the answer is right, I then call a method to make an Invisible JPanel, visible. That works just fine, but the Jpanel itself won't move to the top where its supposed to be. And it needs to fit perfectly since it's just an photoshopped picture of the

Drag and move a picture inside a JLabel with mouseclick

折月煮酒 提交于 2019-11-28 13:06:25
I have an image inside a JLabel. JLabel label = new JLabel(new ImageIcon("C:\\image.jpg")); label.setSize(300,300); I want the following functionality. -I click on a location inside the JLabel (on the image). -With the mousebutton pressed, I can change the location of the image within the JLabel. (I drag the picture to different positions within the JLabel) Well, this means that in many instances the picture will be cropped and outside of view. Please tell me how to implement this functionality? What are the correct event listeners to add to my JLabel? This is a basic example... It works by

setLocation of Label

三世轮回 提交于 2019-11-28 13:01:38
I have all of the labels working correctly but the userLabel[3] is not positioning properly No matter what I do, the label "Color:" always shows up on the frame with a x-coordinate of 0 and a y-coordinate that is half way down the frame. JLabel[] userLabel = new JLabel[4]; for(int p = 0; p < userLabel.length; p++){ userLabel[p] = new JLabel(); userLabel[p].setSize(100,50); frameSetUp.add(userLabel[p]); } userLabel[0].setText("Width of Frame:"); userLabel[1].setText("Height of Frame:"); userLabel[2].setText("# OF Balls:"); userLabel[3].setText("Color:"); userLabel[0].setLocation(10,35);