Swing/AWT/SWT :: Putting Button In JPanel
Jul 3, 2014
I am trying to add buttons in a loop to my but when i compile my program i can`t see my buttons. I can see other stuff that added to jpanel ...
static JButton blocks[][];
for (int i = 0; i < block.length; i++) {
for (int j = 0; j < block[i].length; j++) {
block[i][j] = new Block(i, j);
blocks[i][j] = new JButton(i+"");
blocks[i][j].setLayout(new GridLayout((i+1) * 10, (i+1) * 10, 10, 10));
pageAxisPanel.add(blocks[i][j]);
}
}
View Replies
ADVERTISEMENT
Jun 20, 2014
Am trying to add buttons dynamically in a new Jpanel on click of a button. i am getting new Jpanel but not able to see the buttons.
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
//unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
CardLayout cardLayout=(CardLayout)(frmUno.getContentPane().getLayout());
[Code]...
prepareHandsForGuiCode is
public UNODeckMain prepareHandsForGui(UNODeckMain unoDeckMain){
JButton[] btnArr =new JButton[50];
for(int i=0;i<50;i++){
btnArr[i]=new JButton("hi");
panel_player1.add(btnArr[i]);
}return unoDeckMain; }
Am i skipping something ?
View Replies
View Related
Jun 9, 2014
I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;
[Code] ....
here is the code for the jpanel that loads the other jpanel
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
[Code] ...
How do load a jpanel when a button is pressed in another jpanel
View Replies
View Related
Sep 23, 2014
I have two classes - One is Read.java and the other is Display.java
Read.java looks like this
public static void main(String[]args){
File file = new File("test.txt");
try{
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
[Code] ....
Display.java looks like this:
public class Display extends JFrame {
private JComboBox comboBox;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
//method call to access other class
[Code] ....
Instead of having it so it displays the id's to the console,is there a way I can set it straight up to the combo box?
View Replies
View Related
Jan 2, 2014
I am trying to put a button (in a container) on a jpanel in a jframe with a background but the container is covering up the background with white color.Below I have an excellent SCCE:
Java Code:
package drawFramePackage;
//drawFramePackage
// Author: Nathan Nelson
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JFrame;
[code]...
Basically I just need to set the containers background to transparent.
View Replies
View Related
Nov 29, 2014
I am creating a mad libs type program. This section of code is for the user to be able to make their own mad lib template (that people will be able to fill out later). The normal blanks in a mad lib are for verb, noun, adjective, adverb, etc. I cam up with 13 or so of these buttons, but it would be nice that if the user wants to add a button that they think we missed, such as 'Person in the Room' or 'Silly Location'...that the user would be able to do this. I sort of pictured there being a button that says 'add button' or something like that. Is there a ways to do this with the way I've set things up?
public class MadLibs {
public static void main(String[] args) throws IOException {
////////////////////
//TEXT PANE WINDOW//
////////////////////
//Set up a JTextPane object : The JTextPane is a specialized form of the JEditorPane
//designed especially for the editing (and display) of styled text.
final JTextPane pane = new JTextPane();
[Code] ....
View Replies
View Related
Oct 3, 2014
I would like to know the possible ways to put up JInternalFrame over JPanel to achieve the following output.
Is it even Possible because i learned JInternalFrame can only be added to JDesktopPane.?
View Replies
View Related
Feb 19, 2014
Trying to get an image to display in a GUI.
try {
ByteArrayInputStream in = new ByteArrayInputStream(
transferWorker.bOutput
.toByteArray());
BufferedImage bufferedImage = ImageIO
.read(in);
[Code] ....
But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.
View Replies
View Related
Apr 9, 2014
I have a Jframe and i want to add inside 4 different jpanel.This is easy.
what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?
I have try with BorderLayout but not working.
It's a wizard like but not the same.
I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?
View Replies
View Related
Nov 7, 2014
How can I make a call to paintComponent within the JPanel-class, from another Class?
In class TestClass:
public class TestClass {
public TestClass() {
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(500,500);
initComponents();
[Code] .....
View Replies
View Related
Dec 28, 2014
I have been trying to create a chat client which makes use of a scrollable jpanel and at runtime adds JTextFields to the panel.
Panel Initialising
msgPanel = new JPanel(new MigLayout());
msgPanel.setPreferredSize(new Dimension(400,335));
JScrollPane msgPanelScroll = new JScrollPane(msgPanel);
msgPanelScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
msgPanelScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
mainPanel.add(msgPanelScroll,"span 3,alignx center,wrap");
[Code] .....
But now Im facing the following issues. The text field aligns to the center of the panel & on adding more fields the panel accommodates as it can and does not begin scrolling.
Screenshots attatched
View Replies
View Related
Apr 4, 2014
I pick this code from Head first Java
package GUI;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
public class gui5 {
int x=0;
int y=0;
public static void main(String... x) {
[code]...
but just a Jframe is appearing no Jpanel no green color circle?What is wrong with code
View Replies
View Related
Mar 27, 2014
I am try to do an application based in multiples JFrames, each one with its particular responsibilities, and use one JPanel as a menu with buttons that connect one JFrame to another, But this menu is instantiated at run in view (layout made by netbeans) the Main Jframe appears with its internal JPanel, but the instantiated JPanel does not appear or does not show it's buttons. (notice only run method in the second class):
JPanel Menu that will be used in all alone JFrames of application:
public class MenuSuperior extends javax.swing.JPanel {
public MenuSuperior() {
initComponents();
} private void initComponents() {
[Code] .....
View Replies
View Related
Oct 8, 2001
Let me explain by simplifying the GUI to a simple frame in which I have a JCheckbox and a JPanel mypanel.mypanel has a Textfield tf,JComboBox cmb as it's components.So now if I deselect the JCheckbox, all the components in the mypanel should be disabled. I used a code like:
[code]mycheckbox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(mycheckbox.isSelected())
mypanel.setEnabled(true); else
mypanel.setEnabled(false); } });[code]
but the components inside the panels are not disabled. In my actual program I have a large number of different kinds of components in mypanel.So disabling/enabling each of them on each actionPerformed of the mycheckbox will be laborious. Isn't there any way by which I can disable/enable the mypanel to disable/enable all the components in it?
View Replies
View Related
Apr 4, 2014
I trying to replace original (and empty) JPanel in JFrame with my own made one, components does no appear right, when I pass the mouse first button appears:
MainViewClass:
...
private void initComponents() {
...
MenujPanel = new MenuSuperior();
MenujPanel.setBorder(
BorderFactory.createTitledBorder("Dados Pessoais"));
[Code] .....
Here is the video:
View Replies
View Related
Apr 12, 2015
I need to add 2 JLists inside a JPanel for a crossword. The JPanel is located SOUTH and I'm using BorderLayout in the constructor to locate the JPanel.
The problem is, I can't see the 2 JLists inside the JPanel. For some strange reason the JLists appear in the center where the crosswordPanel is, even though the clues JPanel method is located SOUTH.
package crossword;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
[code]....
View Replies
View Related
Jun 4, 2014
I have used the following code and I am trying to render a String in the JPanel. The text is getting displayed in the mirror image format.
I understand that there is a problem with .scale(), not able to get an idea about the corrective step. Please run the below class.
class Surface extends JPanel {
final int PAD = 40;
private void doDrawing(Graphics g)
{
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Code] ....
View Replies
View Related
Oct 23, 2014
I'd like to enable/disable a jpanel and it's entire contents in one fell swoop. I could of course call each component's .setEnabled() method, but I figured there must be a better way!
View Replies
View Related
Jan 29, 2015
I have created a JFrame that contains 3 JPanel.
My problem is, when i clicked in the bouton to expand the Frame,the 3 JPanel are fixed and do not expanded with the Jframe.
View Replies
View Related
Jan 10, 2014
My JPanel when adding components to it will never make its self larger but it will make my components inside smaller even though I have set the minimum and preferred sizes for those components? I am using the GridBagLayout for my layout manager as I am trying to get used to it.
package manning;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
[code]....
View Replies
View Related
Apr 7, 2015
I want to delete the shape i have drawn on the panel. Here is my code
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
[Code] ....
Why it is not deleting my rectangle.
View Replies
View Related
Dec 9, 2014
I'm writing a Java Swing program for my software development class to allow a user to create a map for a side scroller video game. I'm stuck on a particular part of my GUI where I'm trying to create a properties box for specific tiles. When I draw the components onto the JPanel and display it as it is, it shows two check boxes per row. On the ScrollPane however, all the check boxes go straight onto one line and draw out the scroll pane. Right now I am only concerned with just making the basic GUI.
Here is what I have so far:
Within the main class, I am creating the JFrame and adding components to it. I am attempting to create a JScrollPane which will hold the properties check boxes...
Here is the method where I am implementing the code. It works, but it doesn't display correctly.
private void createPropertiesBox() {
PropertiesBoxPanel pbp = new PropertiesBoxPanel();
propertiesBox = new JScrollPane(pbp);
propertiesBox.setViewportView(pbp);
frame.add(propertiesBox);
[Code] .....
I've been tinkering with this code for quite some time now and I cannot seem to make a breakthrough on how to fix this.
View Replies
View Related
May 4, 2015
there is a main JPanel in my application in that main JPanel i want to add two JPanels with a seperator in between . Though i have added the seperator but its taking some extra space and when i am changing its size , there is no effect . how can i remove/reduce this extra space taken by JSeperator? below is view logic ,
mainPanel = new JPanel(new GridLayout());
jp = new JPanel(new GridLayout(8, 2, 5, 5));
jp2 = new JPanel(new GridLayout(8, 1, 5, 5));
jText = new JTextField(10);
jText2 = new JTextField(10);
jText3 = new JTextField(10);
[code]....
View Replies
View Related
Apr 14, 2015
I am trying to plot a graph and graph should display when JButton is clicked. To create data set, I am taking some value through JTextField and then created a chart and plotted it. I've got a problems: the chart doesn't refresh/update when I change the text field value.
public class Test2 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private ChartPanel chartPanel;
private JTextField textField_1;
double a;
[Code] ....
View Replies
View Related
Jan 15, 2014
I am having problems trying to get my jPanel to display my drawings properly after scrolling. (My drawings is done using by overriding the paint() method as the paintComponent() method does not work in my case.) My jPanel is component of my JScrollpane, and my JScrollpane is part of my jFrame.
The organization of components is: JFrame <-- JScrollPane <-- JPanel ( <-- means added to).
Situation: My drawings did appear when the frame becomes start, but when I start scrolling the scrollbar in any direction, it starts to eat up my drawing leaving only part of drawing which is not affected by scrolling.
I want my jpanel to display the drawing properly even after scrolling in both vertical and horizontal directions. I did use revalidate and repaint methods in my method for start of the JFrame.
Some Ways which I have tried:
1) I have tried adding this.revalidate() and this.repaint() method to the paint() method which did retains the image, but the jPanel keeps blinking on my screen which is trying attempt to update the drawing in a recursive manner.
2) I have tried panel.repaint() and panel.revalidate() in my paint() method, but it did not display my drawing.
3) I have read from other sources that I needed a listener to do it, but I am not sure how it works.
// Code Use for Listener
jScrollPane1.getViewport().addChangeListener(new ListenAdditionsScrolled());
public class ListenAdditionsScrolled implements ChangeListener {
public void stateChanged(ChangeEvent e) {
jPanel3.revalidate();
jPanel3.repaint();
}
}
View Replies
View Related
Feb 5, 2015
I have a problem with the size of my scrollPane. It won't fill the space in the JPanel.
is there a way to let the scrollPane fill the whole space?
View Replies
View Related