All Questions
12 questions
-1
votes
1
answer
103
views
Components not appearing in ContentPane
In my application I have a list of 6 Jlabels, which are added to the contentPane in a for loop. After that I add 2 JButtons - one for removing all the labels and the second one for adding them again:
...
1
vote
1
answer
372
views
How do you overlap components in the grid layout?
For my senior project I am coding a game in Java. It has a grid of square that you need to navigate through in order to complete the goal. I found that grid layout does what I need it to except that I ...
1
vote
0
answers
85
views
JLabel (component) as image - how do i get the file name of the image?
I was wondering how can i get the File name of the image in a JLabel?
-note- i only have the JLabel nothing else
What i've tried:
public static String get(Component c){
String s = c.getName();
...
0
votes
2
answers
3k
views
Printing out sentences in JLabel
How to print out a new sentence or line in JLabel, without changing the last line that was printed? or do I have to use another component?
0
votes
1
answer
556
views
JLabel text in narrow column instead of spread out
I am trying to have a frame that has a JLabel on it. I have succeeded in adding it to the frame but the text shows up in a narrow column instead of taking up more space in the window. How do I fix ...
1
vote
0
answers
226
views
Java: Use component with name from variable [duplicate]
I just wanna know if there's a way to do something like this:
I have 100 jLabel ( jLabel1, jLabel2 ... jLabel100 ) and i have a int variable ( 32 ). I wanna use the Label with the variable name ( ...
0
votes
0
answers
38
views
Java Component Placing
Why is the grass image not at the top of the JFrame? And why isn't the character starting at location 200, 200. He only moves once I click a key. Can anybody explain to me why I am having these ...
1
vote
2
answers
4k
views
accessing swing component of other class
I have two classes mainpanel.java and subpanel.java. The subpanel.class contains a checkbox and some labels. I want to change the setSelected() and setText() of these components when i click some ...
0
votes
3
answers
83
views
Invalid method for multiple components
The code has been simplified considerably as to only highlight the issue. I'm not certain this is the best way to approach this problem either.
I'm attempting to make an object that can have any ...
4
votes
3
answers
4k
views
How do I move a component in a layout?
How do I move a component in a frame while I am using a layout? I have tried this:
System.out.println(test1.getLocation());
int oy = test1.getY();
int ox = test1.getX();
oy++;
ox++...
0
votes
2
answers
4k
views
How do I detect the collison of components?
How do I detect the collision of components, specifically JLabels (or ImageIcons?)? I have tried this:
add(test1);
test1.setLocation(x, y);
add(test2);
test1.setLocation(x1, y1);
validate();
if(...
4
votes
4
answers
9k
views
How do I get a JLabel to accurately predict how wide it should be?
I have a situation where a user enters a String and my code makes a Jlabel for it and attempts to center it on a full screen JFrame/Pane. My problem is, to be able to accurately center it, I need to ...