Unable to introduce Text in next line when using Header Checkbox - java

I'm definitely not the best at explaining problem but let me try.
I have an applet with me. In a JTabel I have one column as checkbox.
I want to have text added to it in the header only such that I have some text and than in the next line I have the checkbox. Using headerRenderer setText is not helping my cause as it appends the test to the checkbox instead of introducing a new line. Moreover I would like to avoid using JPanel because I think it will create lot more problems for me.
Can anyone suggest how I can get this done?
If JPanel is the only option can someone tell me how do I use that.

The Q&A How can I put a control in the JTableHeader of a JTable? includes several important caveats and shows an example using JToggleButton. In this case you want a two line JCheckBox without the complication of an enclosing JPanel.
You might look at implementing the Icon interface, as illustrated here for a TableCellRenderer. This would allow you to leverage the control offered by the component's horizontal and vertical alignment. For consistency, use the UI properties of the JCheckBox for the text, as shown in SelectAllHeader. I'd try rendering a JLabel in paintIcon (), but TextLayout, illustrated here, is an alternative way to get the correct metrics.

Related

What GUI component should I use?

I am working on my homework assignment and I have to achieve the following layout. Can anyone guide me as to how to achieve the right side of the view? I have already coded the left part, it's just the right side that I don't know what to use?
Calendar GUI
Should I just use paintComponent or a JTable?
JTable doesn't seems to suit your needs. You can consider using an array of JTextArea which will be added into a JScrollPane.
In this case, you can make use of the existing behaviours from these JComponents, such as setting them as editable/non-editable. Auto scrolling for JTextArea. JTextArea also allows displaying of multiple lines of records.
Should I just use paintComponent
I supposed you meant by custom painting. Using custom painting will give you alot of freedom to do your own customizations, however if the current JComponents are able to fulfill you needs, then I think you shouldn't try to reinvent the wheel, especially when you need to deal with printing text. Aligning the text properly in custom painting could cost you alot more time than learning how to use various existing JComponents.

difference between Jlabel and noneditable JTextField

Forgive me if this question is trivial. I am not a GUI expert. However, i need to create a Swing control in which the text will only be inserted programmatically based on some calculation (user input never allowed). Are there any preferences here to use JLabel vs. noneditable JTextField? I understand that both will work, but just curious if it is better to use one or another in such circumstances.
Unlike a JLabel, a non-editable JTextField can still be scrolled horizontally to see text that would be replaced by ellipses in a JLabel. More on the latter can be seen here.
The difference is how they look and behave. Also you can cut(&paste) from JTextField.

Synthetica JButton Margins

So, I have a Calendar solution for my employers where I am using a custom look and feel (Synthetica) and each cell in the table holds a JPanel with a list of buttons and a PAGE_AXIS BoxLayout. I am trying to reduce the gaps between each button so that they abut each other, and I've tried setting the borders to null except that destroys the button appearance. I have used the following (as recommended by Oracle to view the actual size of the components) code;
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.red),
getBorder()));
And this is what I get;
Setting the margin does not work with whatever border version the buttons are using. So, is there any way to find the current border that it's using? So that I can set that border's insets manually, or something like that. Basically, I need the buttons to abut each other. Any ideas?
Clarification: I want the button's themselves to stay the same size, but I want the white space around them (highlighted inside of the red borders) to be gone,
Several possibilities should be considered:
Manipulate the button's bound properties: setBorderPainted(false), et al., as suggested here.
See if a suitable sizeVariant is available, as shown here.
Use a custom UI delegate based on BasicButtonUI, as shown here and here.
I tried to get the Synthetica L&F to have a look but seems as though you have to create an account which I did not want to do. Anyways, a quick look around the website and I found a page which indicates how you can see and configure some of the values set in the L&F. Might be worth having a look there.
http://www.jyloo.com/synthetica/customize/

How to find if image is clicked in JApplet?

It is to support image dragging. How to find if an image is clicked in JApplet?
I'm sure there is an easy way to do this, but I've looked everywhere and cannot seem to find it.
Options:
Use a JLabel to hold the image, and give it a MouseListener. Simple.
Or create a JButtton and use the Image as the button's ImageIcon. Probably simpler.
See the Drag and Drop and Data Transfer lesson of the tutorial.
If the purpose of the dragging is to change the order in a slideshow or similar, look to a JList. See setDragEnabled(true) & How to Use Lists for more details.
For the display component, I would recommend a JLabel as suggested by #Hover. JList uses a JLabel as the rendering component by default.

Suggestion regarding which layout to use while implementing GUI in java

I have been working on my assignment and I need a help regarding which layout to choose while designing the label combo box and buttons using java GUI. I want things to be done in a particular manner where in one horizontal line I need labels followed by combo box followed by button in second horizontal line I want the same things with one extra button and so on for third and fourth horizontal line. Actually my concern is that I am very much new to GUI and I need a suggestion which layout to choose and how to implement it
thanks in advance
I would go with GroupLayout (use NetBeans, it has a very good GUI builder, that makes UI creation easy). If you want to try more sophisticated solution, you may check JGoodies or MigLayout.

Categories