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
Related
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
when I increase and decrease the size of frame by cursor , all the contents within JFrame should increase and decrease with the JFrame. If I fix the size of other component within frame, it should increase but should not decrease from its fixed size.
You need to use some LayoutManager, only then all the components inside it will resize with the parent frame. (Also it will try to keep the ratio, depending on manager you choose) There are good examples on this link, first write simple layouts and then make more complex. If this was your question in the first place of course.
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.
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);
}
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
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'm working on a school project. I am writing Sudoku. A Sudoku block consist of 9x9 blocks. Of those 9x9 blocks the Sudoku is divided into 3x3 blocks (9 of them).
How do I color those 3x3 blocks the same color to be able to see in what block your working in (i.e. background colors)?
The cells in a JTable can be styled using a custom TableCellRenderer, which provides a flyweight component ( for example a JLabel) to render each cell. When the cell is editable, you also specify a custom TableCellEditor, which may or may not follow the same style as the renderer.
The UI state (such as the current cell you're working on, to color the group of cells) is best kept in a presentation model (can be a simple bean), which is accessible from your cell renderer and editor, to decide how to style the cell.