Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:33:19+00:00 2026-06-06T14:33:19+00:00

I’ve been tried to put a button at my class at Jython. I’m using

  • 0

I’ve been tried to put a button at my class at Jython. I’m using SWT components to create my GUI. The button doesn’t appear, but the window appear normally. I already create this class at Java, and works well.

This is my code, what is wrong?

from java.lang import Thread as JThread, InterruptedException
from org.eclipse.swt import widgets, layout, SWT 
from org.eclipse.swt.layout import GridLayout, GridData, FillLayout
from org.eclipse.swt.widgets import Composite, Listener#, Event
from org.yakindu.sct.runtime.java.new64 import New64CycleBasedStatemachine
import time

class Cycle(object):
    def __init__(self):

        self.display = widgets.Display()
        self.shell = widgets.Shell(self.display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL)
        self.shell.setLayout(layout.RowLayout())
        self.shell.setText("Message Window")
        self.shell.setLocation(300, 300)
        self.shell.setSize(300, 150)
        self.thread = JThread()
        self.shell.open()

    def run(self):
        self.statemachine = New64CycleBasedStatemachine()
        self.statemachine.enter()
        while not self.thread.isInterrupted():
            self.statemachine.getInterfaceNewTest().getVarMessage()
            self.statemachine.runCycle()
            try: 
                time.sleep(100)
            except InterruptedException: 
                self.thread.interrupt()


        self.thread.start()

    def show_window(self):
        while not self.shell.isDisposed():
            if not self.display.readAndDispatch():
                self.display.sleep()
        self.display.dispose()

        self.thread.interrupted()

    def create_button(self, statemachine, shell):
        self.buttonComposite = Composite(shell, SWT.NO_SCROLL)
        self.buttonCompositeGridData =  GridData()
        self.buttonCompositeGridData.horizontalAlignment = GridData.FILL
        self.buttonCompositeGridData.grabExcessHorizontalSpace = True
        self.buttonComposite.setLayoutData(self.buttonCompositeGridData)
        self.buttonCompositeLayout = FillLayout()
        self.buttonCompositeLayout.type = SWT.HORIZONTAL
        fillLayout = FillLayout()

        self.buttonComposite.setLayout(fillLayout)
        self.button = widgets.Button(self.buttonComposite, SWT.PUSH);
        self.button.setText("Ok")


foo = Cycle()
foo.run()
foo.create_button()
foo.show_window()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:33:21+00:00Added an answer on June 6, 2026 at 2:33 pm

    There are multiple issues:

    1. The position of the self.shell.open(). You are calling create_button() after opening the shell !! See the javadoc of shell.open().
    2. You are using RowLayout, then creating a GridData and then setting a FillLayout. I won’t tell you the problem. Run the code and see.

    Working Example From Your Snippet

    from java.lang import Thread as JThread, InterruptedException
    from org.eclipse.swt import widgets, layout, SWT 
    from org.eclipse.swt.layout import GridLayout, GridData, FillLayout
    from org.eclipse.swt.widgets import Composite, Listener#, Event
    
    import time
    
    class Cycle(object):
        def __init__(self):
    
            self.display = widgets.Display()
            self.shell = widgets.Shell(self.display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL)
            self.shell.setLayout(layout.RowLayout())
            self.shell.setText("Message Window")
            self.shell.setLocation(300, 300)
            self.shell.setSize(300, 150)
    
        def show_window(self):
            self.shell.open() // I have moved it here. After all the control creation !!
            while not self.shell.isDisposed():
                if not self.display.readAndDispatch():
                    self.display.sleep()
            self.display.dispose()
    
    
        def create_button(self):
            self.buttonComposite = Composite(self.shell, SWT.NO_SCROLL)
            #self.buttonCompositeGridData =  GridData()
            #self.buttonCompositeGridData.horizontalAlignment = GridData.FILL
            #self.buttonCompositeGridData.grabExcessHorizontalSpace = True
            #self.buttonComposite.setLayoutData(self.buttonCompositeGridData)
            self.buttonCompositeLayout = FillLayout()
            self.buttonCompositeLayout.type = SWT.HORIZONTAL
            fillLayout = FillLayout()
    
            self.buttonComposite.setLayout(fillLayout)
            self.button = widgets.Button(self.buttonComposite, SWT.PUSH);
            self.button.setText("Ok")
    
    
    foo = Cycle()
    foo.create_button()
    foo.show_window()
    

    Output-

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.