Hey, so here's an example of what I want to do:
This "window" if you will, or simple gui, will accept an ArrayList<String> and in turn spit out for every one of them a checkbox and a text field where you can rename it to whatever name you chose (later I'll add something to check and make sure none of the names are the same... but for now it doesn't matter).
I'm not very familiar with GUI in java so I don't know the best way of doing this. I'm not asking for code, but simply some help in the right direction. I've downloading all of java swing's tutorial demos and examples and have looked at just about every component and layout example in there. Still I don't feel like I know what I'm doing and you'll see in my code soon what I mean.
Before I do I want to show you guys what I want the gui to look like in a sense: -
ArrayList<String> temp = new ArrayList<String>(2);
-
temp.add("First Tag\\");
-
temp.add("Second Tag\\");
-
-
If above is the arraylist I would want the gui to look something like this:
-
-
Note: ---- represents the border of the window, [] represents a checkbox, text represents non-editable text and "text" represents editable text
-
-
Well I didn't mention this earlier but the point of the checkboxes is to not include those strings, when I return an arraylist later, but that's not important now. The gui showing up is coming first...
-
----------------------------------------------
-
- []First Tag: "First Tag" -
-
- []Second Tag: "Second Tag" -
-
----------------------------------------------
-
-
Of course with a title and minimize/maximize/close buttons there too, but they come automatically...
-
Here's what I've got so far with the code, I tried to put stuff into JPanels and then add them to the gui later: -
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
import java.util.*;
-
-
public class TagChoosingWindow implements ItemListener {
-
JTextField[] textFields;
-
JCheckBox[] checkBoxes;
-
JPanel[] panels;
-
-
short[] included;
-
-
ArrayList<String> tags;
-
-
public TagChoosingWindow(ArrayList<String> al) {
-
tags = al;
-
int size = tags.size();
-
-
included = new short[size];
-
-
textFields = new JTextField[size];
-
checkBoxes = new JCheckBox[size];
-
panels = new JPanel[size];
-
-
for (int i = 0; i < size; i++) {
-
checkBoxes[i] = new JCheckBox(tags.get(i) + " : ");
-
checkBoxes[i].setSelected(true);
-
checkBoxes[i].addItemListener(this);
-
-
textFields[i] = new JTextField(tags.get(i));
-
-
included[i] = 1;
-
-
panels[i] = new JPanel(new BoxLayout(panels[i], BoxLayout.LINE_AXIS));
-
panels[i].add(checkBoxes[i]);
-
panels[i].add(textFields[i]);
-
}
-
-
-
}
-
-
private void buildUI(Container container) {
-
container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
-
-
for (int i = 0; i < panels.length; i++) {
-
container.add(panels[i]);
-
}
-
}
-
-
public void itemStateChanged(ItemEvent e) {
-
Object source = e.getItemSelectable();
-
int index = -1;
-
for (int i = 0; i < checkBoxes.length; i++) {
-
if (source == checkBoxes[i]) {
-
index = i;
-
break;
-
}
-
}
-
-
if (e.getStateChange() == ItemEvent.SELECTED) {
-
textFields[index].setEnabled(true);
-
included[index] = 1;
-
} else {
-
textFields[index].setEnabled(false);
-
included[index] = 0;
-
}
-
}
-
-
private void createAndShowGUI() {
-
//Create and set up the window.
-
JFrame frame = new JFrame("Choose What Data Tags You Want and Name Them");
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-
//Set up the content pane.
-
TagChoosingWindow tagchoosingwindow = new TagChoosingWindow(tags);
-
tagchoosingwindow.buildUI(frame.getContentPane());
-
-
//Display the window.
-
frame.pack();
-
frame.setVisible(true);
-
}
-
-
public static void main(String args[]) {
-
//Schedule a job for the event-dispatching thread:
-
//creating and showing this application's GUI.
-
javax.swing.SwingUtilities.invokeLater(new Runnable() {
-
public void run() {
-
ArrayList<String> temp = new ArrayList<String>(2);
-
temp.add("First Tag\\");
-
temp.add("Second Tag\\");
-
TagChoosingWindow tagchoosingwindow = new TagChoosingWindow(temp);
-
tagchoosingwindow.createAndShowGUI();
-
}
-
});
-
}
-
}
-
Oh and thank you for all help, it's much appreciated,
-blazed
6 1922
Have a look at the JTable component with its TableModel compadre. The first
column could consists of JCheckBoxes and the second column can be a
JTextField. The TableModel receives the List at construction time so it is able
to set up the row dimension of the JTable (there are just two columns).
Of course you have to build your own TableModel for this (check the API docs).
You can build a 'collect' method in your model that collects all the selected
Strings from the JTable.
kind regards,
Jos
Have a look at the JTable component with its TableModel compadre. The first
column could consists of JCheckBoxes and the second column can be a
JTextField. The TableModel receives the List at construction time so it is able
to set up the row dimension of the JTable (there are just two columns).
Of course you have to build your own TableModel for this (check the API docs).
You can build a 'collect' method in your model that collects all the selected
Strings from the JTable.
kind regards,
Jos
A good idea. I was considering a JTable at first, but didn't like the look it gave. What you suggested I think might solve all my problems though because if I had my own built TableModel I'm guessing I could manipulate those lines in between the cells to not appear along with other look-and-feel parts of the table.
Thanks,
-blazed
Well, I took a look at it, that's not exactly what I thought TableModel was... but alright. Maybe there's another way to avoid that ... if not, it doesn't matter I guess...
A good idea. I was considering a JTable at first, but didn't like the look it gave. What you suggested I think might solve all my problems though because if I had my own built TableModel I'm guessing I could manipulate those lines in between the cells to not appear along with other look-and-feel parts of the table.
Thanks,
-blazed
Well, I took a look at it, that's not exactly what I thought TableModel was... but alright. Maybe there's another way to avoid that ... if not, it doesn't matter I guess...
You have to read a bit further: there's an AbstractTableModel class that does
the bulk of the work for you; you only have to implement three or four methods:
row and column sizes, get a value and set a value. That's all there is to it. The
AbstractModel class does the rest for you. For most of the 'complicated'
interfaces there's an Abstract class implementation for you (e.g. AbstractList,
AbstractTableModel etc.) so you don't have to (re)implement all the boring
bookkeeping stuff yourself.
kind regards,
Jos
You have to read a bit further: there's an AbstractTable model that does the bulk
of the work for you; you only have to implement three or four methods: row and
column sizes, get a value and set a value. That's all there is to it. The Abstract
thing does the rest for you. For most of the 'complicated' interfaces there's an
Abstract implementation for you (e.g. AbstractList, AbstractTableModel etc.)
so you don't have to (re)implement all the boring bookkeeping stuff yourself.
kind regards,
Jos
Well, I did take a look at that, but it doesn't seem to be able to do what I want:
mainpulate the table so there are no borders between the individual cells or specific cells (like a border between the columns, but not the rows or vice versa)
I may be wrong. I will have to investigate further... I do notice in the "How to use tables" tutorial you can change the background, which is sweet. I never like looking into a lightbulb ;)
-blazed
Well, I did take a look at that, but it doesn't seem to be able to do what I want:
mainpulate the table so there are no borders between the individual cells or specific cells (like a border between the columns, but not the rows or vice versa)
I may be wrong. I will have to investigate further... I do notice in the "How to use tables" tutorial you can change the background, which is sweet. I never like looking into a lightbulb ;)
-blazed
Swing components don't work that way: the Model takes care of the data.
the visual component (the JTable) takes care of the rendering; Hava a look at the setInterCellSpacing() method for example.
kind regards,
Jos
Swing components don't work that way: the Model takes care of the data.
the visual component (the JTable) takes care of the rendering; Hava a look at the setInterCellSpacing() method for example.
kind regards,
Jos
I think I found a solution to my problem. You can use the setBackground with setGridColor to set them as the same color and poof... no more grid! hehe!
-blazed
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anthony Williams |
last post by:
Good morning,
I'm currently designing a site, using CSS, and wish to create a variable
width two-column layout, with header and footer, and one fixed-width column
on the left.
Previously, I...
|
by: Neal |
last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog
entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A
quite good article.
|
by: Matt Bostock |
last post by:
Hi,
I'm a bit of a CSS newbie so please accept my apologies if this post is
inappropriate.
I can't get the 'latest news' title to move across to the right column
where it belongs. Here's a...
|
by: Tammy |
last post by:
What would be a good alternative to using frames? I need something
that will section my webpage into two halves and can change both
frames on a single click.
Thanks in Advance,
Tammy
|
by: Samuel Shulman |
last post by:
I am looking for good guidance for positioning controls on the
form.document, it is absolute nightmare and I don't know where to begin
Thank you,
Samuel Shulman
|
by: dlogan |
last post by:
Since this is becoming a complete hack-job, I think its about time I asked for some help. I am trying to make a calendar using AJAX to allow for the main calendar to display, then load in the events...
|
by: magicofureyes |
last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say
'''' Your...
|
by: Chrisjc |
last post by:
Okay so here is the break down. I have 3 pages.
Index.php
conversionTable.php
convertPost.php
Now my issue is the following.
Everything works just fine however
|
by: hzgt9b |
last post by:
Using VS2005 (.NET 2.0), VB.NET,
I have a windows forms application. I have a StatusStrip containing a
ToolStripStatusLabal and a ToolStripProgressBar.
I want to force the status label to behave...
|
by: fauxanadu |
last post by:
I have a new document open in print layout. Then I attempt to insert an autoshape into the document. As soon as I click on the shape I want to input, word swaps into web layout and does nothing...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |