Swing/AWT/SWT :: How To Reduce Jlabel With Selection Border Around It At Run Time

Sep 14, 2014

I am working on a project (assignment) and i want to be able to click on jlabel and the select border will show (as shown in the image attached) and i used it to resize the jlabel. I tried

@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
setPreferredSize(getSize());
}
});`

yet is not working. I tried some other code that are not working.

View Replies


ADVERTISEMENT

How To Reduce Time In Java

Jul 3, 2014

I have two string representations of time in "HH:MM:SS" and I want to minus one time from the other.

For example if a = 10:20:30 and b = 00:50:20, i would get 09:30:10. What is the best way to do this?

View Replies View Related

Swing/AWT/SWT :: How To Remove Jtable Border

Apr 26, 2015

How can I remove the light blue border? I tried everything that I know [URL]

View Replies View Related

Swing/AWT/SWT :: Using Image As Button - Remove Border?

Oct 10, 2014

I tried a few things and I was unsuccessful at removing the border around my image button. It seemed simple enough when reading on StackOverflow but I'm still getting errors : s

ImageIcon cardIcon_1_1 = new ImageIcon("../images/empty.png");
JLabel cardImg_1_1 = new JLabel(cardIcon_1_1);
cardImg_1_1.setBorder(BorderFactory.createEmptyBorder());
cardImg_1_1.setContentAreaFilled(false);

Errors:

Multiple markers at this line
- Syntax error on token ";", @ expected
- Syntax error on token ".", @ expected after this token

Multiple markers at this line
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error, insert "SimpleName" to complete
QualifiedName
- Syntax error, insert ")" to complete MethodDeclaration

I'm using an applet it had to be in the initialize part of my program...

View Replies View Related

Swing/AWT/SWT :: Netbeans GUI Creator With Border And Gridbag Layouts?

Jan 6, 2014

I'm trying to use netbeans GUI creator to create a chessprogram. However, the default "freeflow" layout is very difficult to work with. However, when I switch the layout to gridbag or border layout, I can't figure out really how to do anything. I don't know how to resize or position elements. Any good set of tutorials for using netbeans GUI creator with non standard layouts?

(I originally used absolute layout, which I can easily add and position elements in, but which I abandoned because i want the chessboard squares to resize when the window changes size).

View Replies View Related

Swing/AWT/SWT :: Graphics2D / Drawing Double Rounded Corners Border?

Mar 26, 2014

I am struggling to make a double border which has rounded corners. The border should be 2 parallel lines.

I made something which looks almost good, but if you look closer there are a few wrong things.To achieve this, I made 2 paths, then painted them in 2 different colours.

The main problem is painting with AA, because the colours overlap and are affected.

I think it would be smoother to paint a single path using 2 colours.

For the first problem, I think some kind of a stroke would be enough. But, if I build a stroke, it's almost same thing like drawing the path twice, like I did before. Anyway i think that would fix AA problem. But still, maybe I can achieve a smoother effect for the corners.

Question:Maybe something with a 2x1 Texture ? It's possible to achieve this ? I know I tried this before and when a curve was encountered the direction of the texture was wrong and looked messy.

PS: Ignore the blueish thing, it's a dragged component to activate the highlight border.

View Replies View Related

Swing/AWT/SWT :: JLabel Does Not Display

May 8, 2014

I'm having problems getting my program to display a JLabel. The program draws shapes of random size and color across a panel. I have this part working. (There is more code for the drawing of shapes, I left it out for easier reading). When I try to add a JLabel in the main method, it does not display.

import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestDraw {

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Rotate JLabel

Jul 21, 2014

I have written a code to rotate a Jlabel but i am facing some problems.

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Can Mig Layout Work As Border Layout

Jun 1, 2014

I want to add only one button in a JFrame by using Mig Layout, dock south as BorderLayout.South does . Is it possible?

View Replies View Related

Swing/AWT/SWT :: How To Access Elements Of TreeViewer Selection

Dec 27, 2014

I have a hierarchical data structure (Machine, Component, Measurement, Fault are classes) displayed in a TreeViewer. I have added SelectionChanged and DoubleClick listeners, but can't find a way to get to the data stored in the selected instance of the data structure class. For example, the selection is a Measurement which has a String name field. I can see the data in the Element in Debug-Variables, but I can't find any getters to access it. I tried casting the selection as a Measurement but it is an ISelection, or TreeSelection class and it won't accept the cast.

It seems there should be get methods to access the data in the selection, but there aren't, so I'm must be missing something fundamental.

View Replies View Related

Swing/AWT/SWT :: Access JLabel From Another Class

May 6, 2014

How can I access to a jLabel of a class from another class or edit its text?

View Replies View Related

Swing/AWT/SWT :: How To Set Opacity Of JLabel And Image

Feb 27, 2014

I'm trying to make a JLabel with an image fade in from transparent to fully visible.Is this possible with the JLabel itself or would I have to change the Image? If I'd have to change the Image's opacity how would I do this?

View Replies View Related

Swing/AWT/SWT :: How To Fill Text Fields With Selection From JList

May 2, 2015

I have an addressBook GUI where I have a JList that populates with the contacts names, and once I double click a contacts name I'm wanting to fill the textfields with the contacts corresponding data.

ex) ContactType: Family (enum), Name: Zoidberg, Address: 111 Space Drive, City: New York City, etc...

I've got it to where I select open from the JMenu, it populates the JList, but once I select a contacts name, all the textfields are populated, but only with the contacts name

ex) Name: Zoidberg, Address: Zoidberg, City: Zoidberg, etc....

What am i doing wrong here, and how can i fix it to where it fills out the correct data?

Here's my code so far:

public class AddressBookGUI extends JFrame {
private final int WIDTH = 450;
private final int HEIGHT = 300;
private JLabel currentlySelected;
private JTextField contactTypeTextField;

[code]...

I'm certain the logic is messed up near the end where i set all text fields to the index, because no matter what field i want to fill it's at it's going to set it to whatever index I select, but I don't know how to fix it.

View Replies View Related

Swing/AWT/SWT :: JTable Using CTRL / Click For Multiple Row Selection

Jul 6, 2014

I know how to do single selection, but I would like to do multiple row selection only by using CTRL + click without the option of dragging the mouse to select rows. So the user would have to hit ctrl + click each time to highlight additional rows.

View Replies View Related

Swing/AWT/SWT :: JTable - Cell Keeps Focus After Clear Selection

May 7, 2014

I'm having a small problem using a jTable.

After calling the .clearSelection() methode of the table object, the cell clicked in when selecting the table row, keeps it's focus.

How do I remove the focus of the cell?

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 :: Changing Text Of JLabel From Another Class

May 26, 2014

Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...

After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:

package com.mrgreaper;
import javax.swing.*;
public class MainWindow {
private JPanel mainWindow;
private JLabel playerlbl;
private JLabel playerNamelbl;

[Code] .....

Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!

From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....

I tried adding a getter setter

public void setCharFirst(JLabel charFirst) {
this.charFirst = charFirst;
}
in the MainWindow.class

Then i tried to set it from my main function

MainWindow.setCharFirst("test");

but it cant access it as my main function is static and it is not now can i make it static...

View Replies View Related

Swing/AWT/SWT :: JLabel Not Updating Its Text Dynamically

Nov 18, 2014

why JLabel setText method is not setting up the text dynamically even though i am calling repaint() once i set the text? Code snippet is below

Locale currentLocale = new Locale(panel.getCountryLocal(), panel.getCountry());
ResourceBundle messages = ResourceBundle.getBundle(Constants.messageBundle, currentLocale);
messages = Panel.getMessages();
String displayString = messages.getString("101022");

[code]....

View Replies View Related

Swing/AWT/SWT :: Color To Persist In Cell Of Jtable After ComboBox Selection

May 29, 2014

I have a ComboBox I'm using for a cellEditor. The list of items in the comboBox might have colors behind them, which I've managed to render. What I haven't figured out is a good way to keep the color in the cell after the item is selected.I don't' want to have a persistent comboBox in the cell, i only want to see it when editing that cell.

public TableCellEditor getCellEditor(int row, int col)
{
if (row==theRow && col==theCol)
{
JComboBox<?> combo = new JComboBox<Object>(getPickListEntries());
combo.setRenderer(new PickListRenderer(combo));
combo.setBorder(BorderFactory.createEmptyBorder());
}

[code]....

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 :: Changing Text Of JLabel By Pressing A Button?

Sep 20, 2014

I don't get what I missed in the code. I used the example of changing the text of a button by clicking on it, but instead I also added a JLabel and tried to make the button change its text instead, but it didn't work. What did I do wrong?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Buttone implements ActionListener{
JLabel label;
JButton button;

[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 :: 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 View Related

Reflection To Reduce Boilerplate Code

Jul 17, 2014

I have the following classes:

abstract class BaseClass {
}
(doesn't have to be abstract if not necessary, but currently there is no need for it not to be abstract)

class InheritedClassA extends BaseClass {
DataA a;
DataB b;
DataC c;

[Code] ....

Now, I want to get the elements like follows:

BaseClass b = new InheritedClassA();
DataA dataA = b.getDataA(); //returns the DataA field if it's a data member of the inherited class, otherwise null

I know I could do something like this:

abstract class BaseClass {
public DataA getDataA() {
return null;
}
public DataB getDataB() {
return null;

[Code] ...

and override getters as necessary in the inherited classes:

class InheritedClassA extends BaseClass {
DataA a;
DataB b;
DataC c;

public DataA getDataA() {
return a;

[Code] ...

But this introduces an awful lot of boilerplate code, especially in the BaseClass class. In my current plans, there could easily be over a hundred different Data classes, and I would have to write a method that simply returns null for each.

I read about the @Inject annotation and reflection. Is it possible to reduce or eliminate the boilerplate code with these tricks, possibly by putting new methods into the classes?

View Replies View Related

How To Reduce Number Of Parallel Arrays In Code

Mar 8, 2015

I'm building a text based "game" where you are communicating with this android creature called Gargoid , at a VERY primitive level . how it works is, simply the user type in a sentence which is decoded for meaning by comparing it with a built in list of words in order to figure out what the user is saying, and then reply with a a relevant response also from a list of built in words. the whole thing would look something like this,

user: what is your name
Gargoid : my name is Gargoid, nice to meet you
user: how is the weather
Gargoid: the weather is wonderful

so far I have 11 arrays which are the following

String[] for user typed in words used for comparison to find meaning ..An Array of String[] , 7 so far, to hold what I call the Gargoid dictionary for example String[] greeting={hi,hello,aloha}, words that indicates greeting int[] called frequency to determine which of the 7 arrays have the greatest "relevancy" to what is being said. and finally another String[] for responses here's the actual code, I want you guys to tell me if there's a way to reduce all this never ending number of arrays? and also is this code a good application of object oriented programming?

MainClass
public class GargoidMain {
public static void main(String[] args) {
TheKeyBoard keyboard=new TheKeyBoard();
TheTranslator translator=new TheTranslator();
TheBrain brain=new TheBrain();
translator.translate(keyboard.userSaysWhat());
brain.respond(translator.userSays());

[code]....

View Replies View Related

OO Principles - Reduce Number Of Methods In API Without Losing Any Functionality

Jun 20, 2014

A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?

A. Looser coupling

B. Tighter coupling

C. Lower cohesion

D. Higher cohesion

E. Weaker encapsulation

F. Stronger encapsulation

View Replies View Related







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