How to set the tables in the CENTER of the window - java

Please,can anyone help me for this problem:
I have built the code in the way that each time I press one of the radio buttons on of the 5 tables I have must be visible in the window while the other 4 are invisible.
The only problem I have is to make the content of this table which has 2 colomns,,,Emer and Nota in the center of the second panel,,,because I have separated the window in 3 panels,
The first panel contains the radio buttons which are ok:)
The second panel contains the 5 tables,,,1 for each radioButton,,,I only need that when I press one of the buttons the selected table to show on the CENTER of the second panel.
The third panel contains only one button,but it's fine;)
Plz help me.
If you need the code tell me to write it here and I would like to put a print screen on it,so you can understand better...I hope so.

I can think of a few ways to solves this. The simplest being just remove the existing table from the second panel and add the table you want to see (should be in a scroll pane too). The other is to use something like a card layout and simply switch to the card that corresponds to your radio button.

Related

How do I change the layout of text areas in java swing

I started making this web page for a project and this is what it looks like so far:
but I want to place the text areas as one on top of the other rather than side to side
How i want it to look:
can someone help me out please
https://i.stack.imgur.com/ZzsKS.png
Set the layout of your panel (or whatever component that contains your textareas) to GridLayout with 4 rows and 1 column. This will put all 4 components (2 Labels and 2 TextAreas one after another in a column)
https://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html

(Java) Trying to format the layout of multiple JTables with other elements in a JPanel

I've been working on a Pokemon-themed quiz game in Java (modeled after Sporcle, if you're familiar). Pretty much everything works how I want it to, except for the layout of the different components of the program.
I've never been very good with the different layout managers, and I don't know how to get them to do what I need.
Here's what the window looks like right now:
Now, I'll play around with font sizes later, but the tables themselves look exactly how I want them to. The problem is, I want them to be under the text fields and buttons and stuff. Here's the portion of the code where I add all the components to my JPanel:
panel.add(label,FlowLayout.LEFT); //adding the "big question text"
panel.add(answerfield); //adding the JTextField
panel.add(correctAnswerTracker); //adding the "x / 151" text
for(int x = sPanes.length-1; x >=0; x--) //as you keep adding to left, it gets pushed over, so doing it backwards results in the correct order
panel.add(sPanes[x],FlowLayout.LEFT);
//each table is in a scrollPane, and all my scrollPanes are in the array sPanes, so I'm looping through that to add the tables
panel.add(startStopButton); //button that says "Start"
panel.add(exit); //button that says "Exit
panel.add(timer); //the timer
As you can see, the statements to add the text field, and correct answer tracker are all written before the add statement for the tables, and yet the tables are at the top. Additionally, there's the issue of my tables in that loop being added in the backwards order, so I had to reverse the direction of the loop iterations to get the tables to appear in the correct order. I've tried using stuff like setLocation and setBounds to get my components more where I want them, but nothing happened. Also, everything just appears in a row below the tables (and I know that's what FlowLayout does), but how would I go about customizing exactly where things appear?
Wrap a panel with BorderLayout around ones with FlowLayout. Put all the content that should be above the tables in a panel and add it with BorderLayout.NORTH. Put all the content that should be below the tables in another panel and add it with BorderLayout.SOUTH. Then put the tables in their own panel just as your are now, and add it with BorderLayout.CENTER.
Either use a LayoutManager or setLayout(null). In the latter case, you can move your components around by calling setBounds on them. I've been doing that lately too (not using a LayoutManager), it's quite liberating.

Java create table with a button on the first row

I'm trying to create a table where the first row contains 1 button, and the other rows contain multiple columns. Example picture:
How could I make this?
I've attempted the following: add button to table but that only allows you to add a button like this:
I've looked at other stackOverflow posts, but those answers contain dead links, which are no help to me.
This is relatively easy by placing the button outside the table. Here is how to go about it:
Create a panel with a BorderLayout. Add the table (to a scroll pane) to the CENTER of the border layout. Add the button to the PAGE_START of the border layout. Job done.

I can't resize or move elements on Intellij IDEA GUI designer

I just want to drag and drop them like in Netbeans.
is there any way to get functionality of Netbeans or Eclipse in IDEA?
I had the same problem and I have solved it. You need to create a new row before dragging any new elements. In the left side you will see small green boxes for each row. Right click on the last row's green box and then choose "Insert row after this". Then you can drag and drop any new elements into your newly created row.
You can drag and drop components and alter on which part of the layout they appear. You might need to split a column if you want the component on only the half of a parent.
See: https://www.jetbrains.com/idea/help/placing-gui-components-on-a-form.html
But to set some minimum size or set if a component should grow, you need to look into properties panel of a selected component (on the left).
See: https://www.jetbrains.com/idea/help/setting-component-properties.html

JTable Header contains Image and on top of that image I want to place 3 buttons in a single header

JTable Header contains Image and on top of that image I want to place 3 buttons in a single header. My requirement is to Create a "Play List" table in which user can add their favourite songs.
So in the header I want to put a "Play List" title and "+" button to insert new playlists and "Export" and "Import" buttons.
How I can do that? Thanks in Advance.
I doubt(1) this use-case actually calls for cramming extra components into a JTable header. E.G. Take the UI of DukeBox.
We can see the play list on the left (a JTable) with a Filter text field and Random check-box above it, and the Enqueue & History buttons below.
This was created with a nested layout. The 'outer layout' is BorderLayout, that panel has the table in the CENTER, and nested panels in the NORTH & SOUTH. The NORTH panel has another BorderLayout, while the SOUTH uses a GridLayout.
If using a nested layout does not give you some ideas, I suggest you post a drawing or better, ASCII art, of the UI as it should appear at the smallest size, as well as a representation of it when it is resized (where is the extra width/height assigned?).
1) I have that suspicion every time I hear words to the effect "Wouldn't it be great if we had a component that..?". Of course, there are some classic counter-examples where the standard widget tool-kit seems lacking (e.g. a date picker or switch list), but these are common components to which a name can be put. If the person asking cannot put a 'catchy name' to the custom component, there is a good chance they are over (or under) thinking the matter.

Categories

Resources