Questions tagged [swing]

30848 questions
0

votes
2

answer
16

Views

Why can't I create a shape on jpanel?

I'm working on java gui with socket programming.I want to create jpanel on the jframe with the parameters I send from the server and create random shapes in jpanel. I used this resource to draw shapes: https://github.com/AugustBrenner/Random-Draw-Shape/blob/master/DrawPanel.java my code in jframe is...
d.k
0

votes
1

answer
15

Views

When I run this code, it just freezes while the audio plays. However, I want an animation to run simultaneously with the audio. How can I do this?

I have been trying to animate a character using Java Swing Graphics. I transition from the main screen to a JPanel that is supposed to display an animation simultaneously while audio (WAV file) runs. However, the audio runs first, and then the JPanel is shown & animated instead. How can I fix this e...
AwesomeGuy
1

votes
2

answer
42

Views

Restart timer if mouse is moving

I want to restart my program, if the mouse is not moving for 2 minutes. I tried to set a timer and restart it everytime the mouse moves, but nothing worked so far. Is there someone who can help me with this problem? frame.addMouseMotionListener(new MouseAdapter() { public void mouseMoved(MouseEvent...
1

votes
1

answer
29

Views

Why does my JFrame randomly shrink when starting on Mac?

When working on my mac laptop I have recently noticed that my frame sometimes shrinks when the program starts. It is about 70-90% that it does shrink. It works as expected on a PC but not on any mac I have tried it on. I have tried to narrow it down a bit (to the code below) but from here I can't fi...
Dante Ardström
1

votes
1

answer
53

Views

java.lang.StackOverflowError between two classes

I'm trying to create a JFrame in one class and adding a JPanel to it in my main class, is this not possible? This is my Main class public class Main { JPanel p; JLabel lbl1; public static void main(String[] args) { new Main(); } Main() { new Window(); JPanel p = new JPanel(); JLabel lbl1 = new JLabe...
Frazyhawk
0

votes
0

answer
22

Views

Using same database connection in lifecycle java application

I have a main JFrame and then some JDialog depends on the JFrame. In one JDialog I set up a database connection that after I would like to use in the lifecycle of the application. How is the best way to make that? With object connection public? Could you suggest to me how I could do that? These are...
Luis perez
1

votes
4

answer
10.9k

Views

How to check if a value exists in jTable which I am trying to add?

How to check in jTable the values I am trying to add from jField exists or not ? I am using Vector in jTable.
xoxn-- 1'w3k4n
1

votes
1

answer
983

Views

JTextArea - how to get first index of current line?

Suppose I have a JTextArea and I want to replace current line with a specific text: Example 123 123455 68967869 gh Now I want to replace text of current cursor existing line. So if cursor in the 3rd line, output will be: 123 123455 replaced text gh Now I have this code. But it just append to curren...
while true
1

votes
1

answer
1.3k

Views

How to execute a .java file on clicking a jbutton in jframe?

On clicking the jbutton in a jframe, I want Start.java file to be executed;what to do? The Start.java is executing well. I want the same execution to be done when clicked on jbutton in jframe, please help me out. My jframe code has jbutton private void jButton3MouseClicked(java.awt.event.MouseEvent...
swetha pvl
1

votes
1

answer
1.5k

Views

how to customize jTable header column font size in Netbeans?

I tried to change jtable header font size in Netbeans. but couldn't yet. anyway the table rows font size is changed successfully. Here is the way I used: The output after changes: Problem : The Header font size is not changed. but I want to change that also. so pls help me how to do.
siper camm
1

votes
1

answer
101

Views

java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row

I've made a small application that reads from an excel (xls file) and displays the contents to a JTable. Everything is working fine in eclipse, yet when I create the jar file and try to run it, I get the following issue: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row The weird thing...
colin
1

votes
2

answer
47

Views

Java swing indeterminate JProgressBar starting from the left when reaching end instead of bouncing

I created a JProgressBar in a GUI application, and setted it to 'indeterminate', but I don't like that it bounces instead of restarting every time it reaches the end. What can I do to fix this graphic setting?
Prometal328
1

votes
1

answer
53

Views

Can't add ImageIcon to JFrame

I've been trying to add an image to a JFrame but I can't seem to get it done. I looked at online tutorials and other similar questions but nothing seems to work. ImageIcon wiz = new ImageIcon('wizard.png'); ImageIcon assassin = new ImageIcon('assassin.png'); JFrame frame = new JFrame('Select'); fram...
Syed
1

votes
2

answer
5k

Views

Java Hangman Game

Hi I've been making a hangman game in Java over ther holidays. Im almost done, but i'm having a few problems with repainting/updating the window. So when ever a life is lost, I'm removing the panel and then adding another one, but for some reason it keeps shifting to the left or sometimes to the rig...
user557240
1

votes
2

answer
1k

Views

Semi-transparent cursor [duplicate]

Possible Duplicate: Need to create cursor with watermark image Can somebody help me to create custom semi-transparent cursor in swing? I need to set some image to this cursor and for instance if I'm overlaping some text on panel I need to see this text under my cursor.
Andriy Kushka
1

votes
2

answer
9.9k

Views

Gap between JPanels in GridLayout

The code below produces nine individual JPanels in which are 9 buttons. The nine JPanels are arranged onto a base JPanel using GridLayout. This base JPanel is then placed onto the ContentPane using Border Layout. I'm using borders for the JButtons and each individual JPanel to clearly define thei...
Paul
1

votes
0

answer
270

Views

Adding Google recaptcha to Java Swing

I'm doing a swing client to connect on a site, but it have a recaptcha. So I'd like to grab this recaptcha and put on my application, maybe on a webview, so the user can make it. To manage that, I make a GET request to the site where the captcha are and get the data-sitekey, send this key to my serv...
Felpsaps
1

votes
0

answer
68

Views

How to add JPanel to Graphics?

How can i add JPanel with JButtons to Graphics? I only want to add JButtons, becouse i want to make pause menu. Window Code: public JFrame frame; private BufferedImage image; private Canvas canvas; private BufferStrategy bs; private Graphics g; public Window(GameContainer gc) { image = new BufferedI...
Norbert
1

votes
0

answer
93

Views

How to use Google login API in java desktop application

how to login with Google API in java desktop application.I have generated API code and secrete key but i don't have any idea how to use it in java desktop application?
ritu
1

votes
0

answer
30

Views

JButtons keep resizing in the gridBagLayout after adding a border triggered by a mouseEvent

I have a JPanel split into 3 Cells. Flure is on on the leftPanel of each cell in each of the 16 Particles. Flyr is on the rightPanel of each cell in a 4 by 4 grid. I'm having trouble trying to get my buttons (Flure and Flyr) to not resize whenever I set the border. The border is set whenever the but...
Pvo
0

votes
2

answer
21

Views

How to load exact number of rows to jTable from MySQL and paginate the remaining?

I am trying to load data from MySQL into my Application, where I have a jTable. I want to load only 100 rows using a query, and I can do that successfully as of now. furthermore, I want to paginate that data, in such a way that if I have the next button, and I click on that, the table should be upda...
Hefaz
0

votes
0

answer
6

Views

How to print multiple JTables to a single page when space is available

I have a java application with 2 JTable. The first table is made up of 2 columns and 5 rows always. The second JTable is made up of 4 columns and many columns. I want to print JTable 1 above JTable 2, then continue to print the rest of JTable. How would I do this? From a printable page perspective...
IamAUser12
1

votes
0

answer
21

Views

Force dock name on Fedora with Java Swing

I have a Java Swing application running on several OS. On Fedora, when I start the application the Java main class is displayed with dashes as a menu next to the Applications and Places menu. How can I force this name to be my application name and not the Java class with the full package before? On...
Daniel
1

votes
0

answer
39

Views

how I could getext from menu item when click in groovy

I'm trying to get text with this code but appears error No such property: menuItem for class: Testgroovy How i could correct this error import groovy.swing.* import javax.swing.event.* new SwingBuilder().edt { def fillMenu = { -> scripts.removeAll() String megah='' new File('main/groovy').listFiles(...
user8862613
1

votes
1

answer
289

Views

Calling IntelliJ Swing Forms from another class

I'm just starting out with Java and I've run into this concept that I don't understand. I want to know how I can open a form developed with IntelliJ's Swing Form editor from another class. See below this code works fine in one class. import javax.swing.*; import java.awt.event.ActionEvent; import ja...
Ben Yazolli
1

votes
1

answer
36

Views

JTextArea Output

Good Evening, What can I do to have the output from jTExtArea like in the console? You can see the image how it is, I use .append to show the output in jTextArea Image Code: public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { for (int i = 0; i < a.pattern_cnt; i++) { for (int j =...
John Coffey
1

votes
1

answer
55

Views

Java - Set JFrame Opacity from JMenuItem

I'am trying right now to set the opacity of a JFrame to 50 % from a JMenuItem. My Last try was this: op50.addActionListener((ActionEvent y) -> { setUndecorated(true); AWTUtilities.setWindowOpacity(this, 0.5F); }); But no matter what I'm doing, I run into an java.awt.IllegalComponentStateException E...
xcynthos
1

votes
1

answer
42

Views

Java-FX MenuBar in JFrame/JFXPanel : First click not recognized

I want to place a JavaFX MenuBar over a JFrame (Netbeans RCP). So I have placed a JFXPanel on the JFrame and have kept the FX Menubar over that. But whenever I click the Menu (when it's not focussed), the first click doesn't work. Only the after I click twice, the Menu is shown. [Answer / a work-ar...
Arun Pratap
1

votes
0

answer
63

Views

JSplitPane in JLayeredPane

I want the right content of an JSplitPane to fill the entire available space and the left content (panel) to be on top of the other panel. I was thinking about using a JLayeredPane to solve that problem but I couldn't get it to work. My class currently looks like this: public class LayeredPane exte...
Ubuntix
1

votes
2

answer
48

Views

Dynamic changing of layouts in swing

I am almost certain this question was asked before here: Java Swing: How to change GUI dynamically , but I seem to just have some fundamental misunderstanding in how it works. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class JTest extends J...
goinginsane
1

votes
0

answer
66

Views

Scala Swing scrollbar for TextArea

I'm trying to add a scrollbar to a text area component. I could use FlowPanel, but I need to use GridBagPanel for my other components and when I tried to add a flowpanel inside the gridbagpanel it was empty and like 2x2 pixels. Is there a way to add two panels to a MainFrame or add the scrollbar so...
Alqio
1

votes
0

answer
34

Views

ActionListener from controller doesn't trigger

I have an MVC with swing project with two views, a model and a controller. The controller has as fields a list of models, and a list of views. I tried to add a listener on a button from one of my views: private void initializeNewOrderListeners() { NewOrderView view = (NewOrderView) views.get(0); JBu...
user30771
1

votes
0

answer
72

Views

JTable column sorter shows two arrows

I am using JTable and for the column I am allowing multiple row selection and allowing the table to be sorted. The table has a column which is Boolean(check-box). When this check-box is unselected for all the rows and I sort the table by any of the columns then I can select the rows correctly. But w...
1

votes
0

answer
50

Views

Clear text when you press the JTextField

I'm trying to get the text of the JTextField erased every time I click on it. I made a addFocusListeneBut no word comes out. I do not understand why nick = new JTextField('nick', 5); add(nick); nick.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { nick.setText(''); } pu...
zzxbx
1

votes
1

answer
243

Views

Java How to add menuBar to JFrame without destroying my layout

I need some help with adding a menuBar to my JFrame. I have my Gui class: public class Gui extends JFrame implements KeyListener { private PanelMiniMap map; private CardLayout cardLayout = new CardLayout(); private JPanel cards; public Gui() { this.setSize(1000, 800); this.setDefaultCloseOperation(E...
user3793935
1

votes
0

answer
45

Views

Empty JFrame when adding JLabel & JTextField to it [duplicate]

This question already has an answer here: How to align JLabel-JTextField pairs vertically 7 answers Arrange the Label with its respective field Swing 6 answers Setting JLabels in rows and placing the equivalent JTextField right next to it 2 answers So I am supposed to make a very simple fillout f...
Some Student
1

votes
0

answer
168

Views

Message console on JFrame does not work by double click on jar

So I created a message console. And used append to display messages and it works perfectly by running java -jar JavaProgram, however when I double click on it the application runs and I see the JFrame but nothing is displayed. The text that I did append is not present. By the way, double clicking it...
HashTables
1

votes
0

answer
37

Views

Access frame attribute from component in multi frame environment

Problem I have a multi frame environment. Each JFrame has several JComponents, nested in each other. I need to access a global variable of the frame from within some of the embedded components. I can't use static because the static would of course apply to all frames. I can't hand over the frame or...
Roland
1

votes
0

answer
36

Views

Java GridLayout: new row

I have a JPane GridLayout filled with Buttons (about 30). I want to go to a new row at specific Points. How can I break to the next line? I tried to use the LayoutManager, but I didn't get it to work.
writzlpfrimpft
1

votes
1

answer
95

Views

Java setText not updating after button click

I am making a count up timer using buttons to start and stop. I need help solving this... when I press the 'Start' Button it works (tested using System.out.print) but the setText doesn't update for me. However If put the t.start(); after frame.setVisible(true); instead of after start = 1; the setTex...
Jelly

View additional questions