I want a way to reduce java GUI code [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
suppose I want to design Java GUI frame with 30 radio box on it . Are there any way to add them without write many lines of code may about 60 line ?

for (int i=1; i <30; i++){
//radio check box adding code here
}

Declare all radio button names in an array and do the iteration like following,
String[5] radioString = {"P","Q","R","S","T"}; //declare as much as you want
for(String radioName : radioString){
JRadioButton rectangular = new JRadioButton(radioName);
}

Related

Colouring specific letters in a String? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to change the colour of all 'A's in the string to green and all 'Z's in the string to red colour. I have a string as:
String input = "LENGTH OF THIS STRING IS GREATER THAN ZERO";
I want to output it on the screen (in SWING, see comments) with all letters 'A' colored to green and 'Z' colored to red.
If you are using a Swing component (JLabel, JButton, J...) then you should use some HTML in your Swing component.
Here is an example from official Swing documentation:
button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");
So you can do whatever you want with your text !
I guess this is not the case, but you can also want to 'draw' your text in Canvas, then you should read the documentation about Java2D API

JFrame using one component on two different panels makes it dissapear [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Basically I have two panels and one label. I want this label to show in the exact same position on both panels(I'm using the card layout). But when I use the same component it doesn't show up on either panel, but it does if it's only being used on one panel. Does anyone know why?
Thanks.
No you can't do that. A Swing component can only have 1 parent.
But you might be able to create 2 JLabel objects, and give them the same Model, so they always show/contains the same data.

Take JSpinner back to the last valid value on loss of focus [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
How can I make the JSpinner go back to the last valid value when it loses focus and also when I press the spinner arrow button?
You could use an InputVerifier or adjust the spinner model to provide min/max values. See How to use Spinners

Android Image Looping [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wanted to loop three images switching like this.
http://www.transum.org/software/SW/SnailRace/DiceAnimated.gif
int i=1;
while(i<5000){
enemyj.setImageResource(R.drawable.paper);
i++;
enemyj.setImageResource(R.drawable.rock);
i++;
enemyj.setImageResource(R.drawable.sciss);
i++;
}
the duration is there but there is no image showing. the image afterwards is showing fine
What you need is AnimationDrawable take a look at official page, or check it on google
You just need to use AnimationDrawable.
This is a blocking while loop - only the last setImageResource will be visible to the user.
I suggest you check out Frame Animations: http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

How do I create a Java Swing component that contains only an image and a JLabel? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to make a simple component that does nothing other than draw an arbitrary image, and then directly beneath it place a JLabel for displaying arbitrary text.
How can I achieve this? I'm brand new to Swing and I'm trying to learn as I go, but I don't currently understand how I would go about doing this. I know it's a basic question, and I appreciate any help I can get.
JLabel is your friend:
JLabel label = new JLabel("Your text here");
label.setHorizontalTextPosition(SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setIcon(new ImageIcon(this.getClass().getResource("/path/to/image/image.jpg")));

Categories