Skip to main content

All Questions

Tagged with
-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: ...
Virginia's user avatar
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 ...
William Doering's user avatar
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(); ...
Rof's user avatar
  • 31
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?
Lee's user avatar
  • 41
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 ...
user1881401's user avatar
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 ( ...
user3215982's user avatar
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 ...
Nic's user avatar
  • 98
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 ...
Rohan Kandwal's user avatar
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 ...
H3katonkheir's user avatar
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++...
Coupon22's user avatar
  • 394
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(...
Coupon22's user avatar
  • 394
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 ...
user83643's user avatar
  • 2,971