How do you color certain cells? [closed] - java

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.

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.

get value from jtextfield and set it to jtable in netbeans [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 using netbean gui. i donno the code is it same or not. but atleast i had a rough idea on how to do it.
i had a Jtable, textfield and a Jbutton
i wan to enter something into textfield and after clicking the button, the textfield will draw the data from database and set it to the Jtable. everytime i key in something to text field, i wan the data to be appear in Jtable. is this possible?
i already try using jtable model. but i don't know how to create proper jtable model.
I Suggest you explore your netbeans IDE where UI designing is a piece of cake especially inserting jTextfield, jTable etc......using simple drag and drop.
(There's option to create a swing based java file by default where javax.swing.JFrame or similar classes are extended automatically. Insertion can be done via Design Tab.)
And about getting the functions to read from jTables and jTextfields. I suggest you to check the corresponding javadocs.

using breadcrumb in Swing [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 am working on a project where user faces 5 frames . Each frame contains the data to be filled . so when he completes the one frame and goes to next frame it has to confirm that the data is filled for that I want to use BreadCrumb(or progressbar).
so how to create a BreadCrumb(or progressbar) in java swings
I want to make similar to below image in java swings
I suggest that you
create 5 images to use as your breadcrumb images. Any basic image editing program can help you with this.
Put the 5 images in ImageIcons, and put the ImageIcons in either an array or an ArrayList<ImageIcon>.
Display the current Icon in a JLabel that is part of your GUI. You can easily set the JLabel's Icon via its setIcon(Icon icon) method.
I would strongly urge you not to use "5 frames" since that is an irksome user experience and is not what the user experiences when using a professional application.
Instead create 5 JPanels that handle each part of the process.
Swap these JPanels in and out of your GUI via a CardLayout-using JPanel, one that I assume will sit on top of the JLabel that displays your breadcrumb ImageIcons.
When you swap a JPanel view, you also swap an ImageIcon. This swapping will likely be done in the same method.
Remember that it is Java "Swing", not "swings". Good luck.

Animated drag and drop in JTable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Do you know some way to make drag and drop in table more user-friendly? For example: row stick to mouse on drag, and other rows swap places when dragging. Can you recommend me some library for this ?
I'd suggest you take a little time to have a read through The Rabbit Hole which has some excellent articles on the topic of drag'n'drop.
These are most of the articles of interest
Smooth JList Drop Target Animation
Smooth Tree Drop Animation
My Drag Image is Better than Yours
Dead Simple Drags
Fancy Drops
Drag Images for Everyone
Drop Target Navigation, or you drag your bags, let the doorman get the door
Swing Drag Images (Improved)
Well, Java libraries are usually not good really at the "animation" thing. There is a way to do this using the D and D libraries Java comes with but it would require swapping the values of the rows, rather than swapping the rows themselves.
Java is very limited at this kind of stuff. Either you hard code your own library, or use some other language that has libraries for tasks like these.

Categories